Documentation ¶
Overview ¶
Package decor contains common decorators used by "github.com/vbauerster/mpb" package. Some decorators returned by this package might have a closure state. It is ok to use decorators concurrently, unless you share the same decorator among multiple *mpb.Bar instances. To avoid data races, create new decorator per *mpb.Bar instance. Don't: p := mpb.New() name := decor.Name("bar") p.AddBar(100, mpb.AppendDecorators(name)) p.AddBar(100, mpb.AppendDecorators(name)) Do: p := mpb.New() p.AddBar(100, mpb.AppendDecorators(decor.Name("bar1"))) p.AddBar(100, mpb.AppendDecorators(decor.Name("bar2")))
Index ¶
- Constants
- Variables
- type AmountReceiver
- type CounterKB
- type CounterKiB
- type Decorator
- func AverageETA(style TimeStyle, wcc ...WC) Decorator
- func AverageSpeed(unit int, unitFormat string, wcc ...WC) Decorator
- func Counters(unit int, pairFormat string, wcc ...WC) Decorator
- func CountersKibiByte(pairFormat string, wcc ...WC) Decorator
- func CountersKiloByte(pairFormat string, wcc ...WC) Decorator
- func CountersNoUnit(pairFormat string, wcc ...WC) Decorator
- func Elapsed(style TimeStyle, wcc ...WC) Decorator
- func EwmaETA(style TimeStyle, age float64, wcc ...WC) Decorator
- func EwmaSpeed(unit int, unitFormat string, age float64, wcc ...WC) Decorator
- func MovingAverageETA(style TimeStyle, average MovingAverage, normalizer TimeNormalizer, wcc ...WC) Decorator
- func MovingAverageSpeed(unit int, unitFormat string, average MovingAverage, wcc ...WC) Decorator
- func Name(name string, wcc ...WC) Decorator
- func OnComplete(decorator Decorator, message string) Decorator
- func Percentage(wcc ...WC) Decorator
- func StaticName(name string, wcc ...WC) Decorator
- type MovingAverage
- type OnCompleteMessenger
- type ShutdownListener
- type SpeedKB
- type SpeedKiB
- type Statistics
- type Syncable
- type TimeNormalizer
- type TimeStyle
- type WC
Constants ¶
const ( KiB = 1 << (iota * 10) MiB GiB TiB )
const ( KB = 1000 MB = KB * 1000 GB = MB * 1000 TB = GB * 1000 )
const ( UnitKiB UnitKB )
const ( // DidentRight bit specifies identation direction. // |foo |b | With DidentRight // | foo| b| Without DidentRight DidentRight = 1 << iota // DextraSpace bit adds extra space, makes sense with DSyncWidth only. // When DidentRight bit set, the space will be added to the right, // otherwise to the left. DextraSpace // DSyncWidth bit enables same column width synchronization. // Effective with multiple bars only. DSyncWidth // DSyncWidthR is shortcut for DSyncWidth|DidentRight DSyncWidthR = DSyncWidth | DidentRight // DSyncSpace is shortcut for DSyncWidth|DextraSpace DSyncSpace = DSyncWidth | DextraSpace // DSyncSpaceR is shortcut for DSyncWidth|DextraSpace|DidentRight DSyncSpaceR = DSyncWidth | DextraSpace | DidentRight )
Variables ¶
var ( WCSyncWidth = WC{C: DSyncWidth} WCSyncWidthR = WC{C: DSyncWidthR} WCSyncSpace = WC{C: DSyncSpace} WCSyncSpaceR = WC{C: DSyncSpaceR} )
Global convenience shortcuts
Functions ¶
This section is empty.
Types ¶
type AmountReceiver ¶
AmountReceiver interface. If decorator needs to receive increment amount, so this is the right interface to implement.
type CounterKiB ¶
type CounterKiB int64
type Decorator ¶
type Decorator interface { Decor(*Statistics) string Syncable }
Decorator interface. A decorator must implement this interface, in order to be used with mpb library.
func AverageETA ¶
AverageETA decorator.
`style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS] `wcc` optional WC config
func AverageSpeed ¶
AverageSpeed decorator with dynamic unit measure adjustment.
`unit` one of [0|UnitKiB|UnitKB] zero for no unit `unitFormat` printf compatible verb for value, like "%f" or "%d" `wcc` optional WC config
unitFormat example if UnitKiB is chosen:
"%.1f" = "1.0MiB/s" or "% .1f" = "1.0 MiB/s"
func Counters ¶
Counters decorator with dynamic unit measure adjustment.
`unit` one of [0|UnitKiB|UnitKB] zero for no unit `pairFormat` printf compatible verbs for current and total, like "%f" or "%d" `wcc` optional WC config
pairFormat example if UnitKB is chosen:
"%.1f / %.1f" = "1.0MB / 12.0MB" or "% .1f / % .1f" = "1.0 MB / 12.0 MB"
func CountersKibiByte ¶
CountersKibiByte is a wrapper around Counters with predefined unit UnitKiB (bytes/1024).
func CountersKiloByte ¶
CountersKiloByte is a wrapper around Counters with predefined unit UnitKB (bytes/1000).
func CountersNoUnit ¶
CountersNoUnit is a wrapper around Counters with no unit param.
func Elapsed ¶
Elapsed returns elapsed time decorator.
`style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS] `wcc` optional WC config
func EwmaETA ¶
EwmaETA exponential-weighted-moving-average based ETA decorator.
`style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS] `age` is the previous N samples to average over. `wcc` optional WC config
func EwmaSpeed ¶
EwmaSpeed exponential-weighted-moving-average based speed decorator, with dynamic unit measure adjustment.
`unit` one of [0|UnitKiB|UnitKB] zero for no unit `unitFormat` printf compatible verb for value, like "%f" or "%d" `average` MovingAverage implementation `wcc` optional WC config
unitFormat example if UnitKiB is chosen:
"%.1f" = "1.0MiB/s" or "% .1f" = "1.0 MiB/s"
func MovingAverageETA ¶
func MovingAverageETA(style TimeStyle, average MovingAverage, normalizer TimeNormalizer, wcc ...WC) Decorator
MovingAverageETA decorator relies on MovingAverage implementation to calculate its average.
`style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS] `average` available implementations of MovingAverage [ewma.MovingAverage|NewMedian|NewMedianEwma] `normalizer` available implementations are [NopNormalizer|FixedIntervalTimeNormalizer|MaxTolerateTimeNormalizer] `wcc` optional WC config
func MovingAverageSpeed ¶
func MovingAverageSpeed(unit int, unitFormat string, average MovingAverage, wcc ...WC) Decorator
MovingAverageSpeed decorator relies on MovingAverage implementation to calculate its average.
`unit` one of [0|UnitKiB|UnitKB] zero for no unit `unitFormat` printf compatible verb for value, like "%f" or "%d" `average` MovingAverage implementation `wcc` optional WC config
func OnComplete ¶
OnComplete returns decorator, which wraps provided decorator, with sole purpose to display provided message on complete event.
`decorator` Decorator to wrap `message` message to display on complete event
func StaticName ¶
StaticName returns name decorator.
`name` string to display `wcc` optional WC config
type MovingAverage ¶
MovingAverage is the interface that computes a moving average over a time-series stream of numbers. The average may be over a window or exponentially decaying.
func NewMedian ¶
func NewMedian() MovingAverage
NewMedian is fixed last 3 samples median MovingAverage.
func NewMedianEwma ¶
func NewMedianEwma(age ...float64) MovingAverage
NewMedianEwma is ewma based MovingAverage, which gets its values from median MovingAverage.
type OnCompleteMessenger ¶
type OnCompleteMessenger interface {
OnCompleteMessage(string)
}
OnCompleteMessenger interface. Decorators implementing this interface suppose to return provided string on complete event.
type ShutdownListener ¶
type ShutdownListener interface {
Shutdown()
}
ShutdownListener interface. If decorator needs to be notified once upon bar shutdown event, so this is the right interface to implement.
type Statistics ¶
Statistics is a struct, which gets passed to a Decorator.
type Syncable ¶
Syncable interface. All decorators implement this interface implicitly. Its Syncable method exposes width sync channel, if sync is enabled.
type TimeNormalizer ¶
func FixedIntervalTimeNormalizer ¶
func FixedIntervalTimeNormalizer(updInterval int) TimeNormalizer
func MaxTolerateTimeNormalizer ¶
func MaxTolerateTimeNormalizer(maxTolerate time.Duration) TimeNormalizer
func NopNormalizer ¶
func NopNormalizer() TimeNormalizer
type WC ¶
WC is a struct with two public fields W and C, both of int type. W represents width and C represents bit set of width related config. A decorator should embed WC, in order to become Syncable.