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() eta := decor.ETA(decor.ET_STYLE_GO, 0, startBlock) p.AddBar(100, mpb.AppendDecorators(eta)) p.AddBar(100, mpb.AppendDecorators(eta)) Do: p := mpb.New() p.AddBar(100, mpb.AppendDecorators(decor.ETA(decor.ET_STYLE_GO, 0, startBlock))) p.AddBar(100, mpb.AppendDecorators(decor.ETA(decor.ET_STYLE_GO, 0, startBlock)))
Index ¶
- Constants
- Variables
- type AmountReceiver
- type CounterKB
- type CounterKiB
- type Decorator
- func CountersKibiByte(pairFormat string, wcc ...WC) Decorator
- func CountersKiloByte(pairFormat string, wcc ...WC) Decorator
- func CountersNoUnit(pairFormat string, wcc ...WC) Decorator
- func ETA(style int, age float64, sb chan time.Time, wcc ...WC) Decorator
- func Elapsed(style int, wcc ...WC) Decorator
- func MovingAverageETA(style int, average MovingAverage, sb chan time.Time, wcc ...WC) Decorator
- func MovingAverageSpeed(unit int, unitFormat string, average MovingAverage, sb chan time.Time, ...) Decorator
- func Name(name string, wcc ...WC) Decorator
- func OnComplete(decorator Decorator, message string, wcc ...WC) Decorator
- func Percentage(wcc ...WC) Decorator
- func SpeedKibiByte(unitFormat string, age float64, sb chan time.Time, wcc ...WC) Decorator
- func SpeedKiloByte(unitFormat string, age float64, sb chan time.Time, wcc ...WC) Decorator
- func SpeedNoUnit(unitFormat string, age float64, sb chan time.Time, wcc ...WC) Decorator
- func StaticName(name string, wcc ...WC) Decorator
- type DecoratorFunc
- type MovingAverage
- type OnCompleteMessenger
- type ShutdownListener
- type SpeedKB
- type SpeedKiB
- type Statistics
- 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 )
const ( ET_STYLE_GO = iota ET_STYLE_HHMMSS ET_STYLE_HHMM ET_STYLE_MMSS )
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 ¶
type AmountReceiver interface {
NextAmount(int)
}
type CounterKiB ¶
type CounterKiB int64
type Decorator ¶
type Decorator interface {
Decor(*Statistics, chan<- int, <-chan int) string
}
Decorator is an interface with one method:
Decor(st *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string
All decorators in this package implement this interface.
func CountersKibiByte ¶
CountersKibiByte returns human friendly byte counters decorator, where counters unit is multiple by 1024.
`pairFormat` printf compatible verbs for current and total, like "%f" or "%d" `wcc` optional WC config
pairFormat example:
"%.1f / %.1f" = "1.0MiB / 12.0MiB" or "% .1f / % .1f" = "1.0 MiB / 12.0 MiB"
func CountersKiloByte ¶
CountersKiloByte returns human friendly byte counters decorator, where counters unit is multiple by 1000.
`pairFormat` printf compatible verbs for current and total, like "%f" or "%d" `wcc` optional WC config
pairFormat example:
"%.1f / %.1f" = "1.0MB / 12.0MB" or "% .1f / % .1f" = "1.0 MB / 12.0 MB"
func CountersNoUnit ¶
CountersNoUnit returns raw counters decorator
`pairFormat` printf compatible verbs for current and total, like "%f" or "%d" `wcc` optional WC config
func ETA ¶
ETA returns exponential-weighted-moving-average 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. If zero value provided, it defaults to 30. `sb` is a start block receive channel. User suppose to send time.Now() to this channel on each iteration of a start block, right before actual job. The channel will be auto closed on bar shutdown event, so there is no need to close from user side. `wcc` optional WC config
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 MovingAverageETA ¶
MovingAverageETA returns ETA decorator, which relies on MovingAverage implementation to calculate average. Default ETA decorator relies on ewma implementation. However you're free to provide your own implementation or use alternative one, which is provided by decor package:
decor.MovingAverageETA(decor.ET_STYLE_GO, decor.NewMedian(), sb)
func MovingAverageSpeed ¶
func MovingAverageSpeed(unit int, unitFormat string, average MovingAverage, sb chan time.Time, wcc ...WC) Decorator
MovingAverageSpeed returns Speed decorator, which relies on MovingAverage implementation to calculate average. Default Speed decorator relies on ewma implementation. However you're free to provide your own implementation or use alternative one, which is provided by decor package:
decor.MovingAverageSpeed(decor.UnitKiB, "% .2f", decor.NewMedian(), sb)
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 `wcc` optional WC config
func SpeedKibiByte ¶
SpeedKibiByte returns human friendly I/O operation speed decorator,
`unitFormat` printf compatible verb for value, like "%f" or "%d" `age` is the previous N samples to average over. If zero value provided, it defaults to 30. `sb` is a start block receive channel. User suppose to send time.Now() to this channel on each iteration of a start block, right before actual job. The channel will be auto closed on bar shutdown event, so there is no need to close from user side. `wcc` optional WC config
unitFormat example:
"%.1f" = "1.0MiB/s" or "% .1f" = "1.0 MiB/s"
func SpeedKiloByte ¶
SpeedKiloByte returns human friendly I/O operation speed decorator,
`unitFormat` printf compatible verb for value, like "%f" or "%d" `age` is the previous N samples to average over. If zero value provided, it defaults to 30. `sb` is a start block receive channel. User suppose to send time.Now() to this channel on each iteration of a start block, right before actual job. The channel will be auto closed on bar shutdown event, so there is no need to close from user side. `wcc` optional WC config
unitFormat example:
"%.1f" = "1.0MB/s" or "% .1f" = "1.0 MB/s"
func SpeedNoUnit ¶
SpeedNoUnit returns raw I/O operation speed decorator.
`unitFormat` printf compatible verb for value, like "%f" or "%d" `age` is the previous N samples to average over. If zero value provided, it defaults to 30. `sb` is a start block receive channel. User suppose to send time.Now() to this channel on each iteration of a start block, right before actual job. The channel will be auto closed on bar shutdown event, so there is no need to close from user side. `wcc` optional WC config
unitFormat example:
"%.1f" = "1.0" or "% .1f" = "1.0"
func StaticName ¶
StaticName returns name decorator.
`name` string to display `wcc` optional WC config
type DecoratorFunc ¶
type DecoratorFunc func(*Statistics, chan<- int, <-chan int) string
DecoratorFunc is an adapter for Decorator interface
func (DecoratorFunc) Decor ¶
func (f DecoratorFunc) Decor(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string
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 ¶
OnCompleteMessenger is an interface with one method:
OnCompleteMessage(message string, wc ...WC)
Decorators implementing this interface suppose to return provided string on complete event.
type ShutdownListener ¶
type ShutdownListener interface {
Shutdown()
}
type Statistics ¶
Statistics is a struct, which gets passed to a Decorator.
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.
func (*WC) BuildFormat ¶
func (wc *WC) BuildFormat()
BuildFormat builds initial format according to WC.C