Documentation ¶
Overview ¶
Package decor provides common decorators for "github.com/vbauerster/mpb/v5" module. 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
- func FmtAsSpeed(input fmt.Formatter) fmt.Formatter
- func NewMedian() ewma.MovingAverage
- func NewThreadSafeMovingAverage(average ewma.MovingAverage) ewma.MovingAverage
- type AverageDecorator
- type Configurator
- type DecorFunc
- type Decorator
- func Any(fn DecorFunc, wcc ...WC) Decorator
- func AverageETA(style TimeStyle, wcc ...WC) Decorator
- func AverageSpeed(unit int, format string, wcc ...WC) Decorator
- func Counters(unit int, pairFmt string, wcc ...WC) Decorator
- func CountersKibiByte(pairFmt string, wcc ...WC) Decorator
- func CountersKiloByte(pairFmt string, wcc ...WC) Decorator
- func CountersNoUnit(pairFmt string, wcc ...WC) Decorator
- func Current(unit int, format string, wcc ...WC) Decorator
- func CurrentKibiByte(format string, wcc ...WC) Decorator
- func CurrentKiloByte(format string, wcc ...WC) Decorator
- func CurrentNoUnit(format string, wcc ...WC) Decorator
- func Elapsed(style TimeStyle, wcc ...WC) Decorator
- func EwmaETA(style TimeStyle, age float64, wcc ...WC) Decorator
- func EwmaSpeed(unit int, format string, age float64, wcc ...WC) Decorator
- func InvertedCurrent(unit int, format string, wcc ...WC) Decorator
- func InvertedCurrentKibiByte(format string, wcc ...WC) Decorator
- func InvertedCurrentKiloByte(format string, wcc ...WC) Decorator
- func InvertedCurrentNoUnit(format string, wcc ...WC) Decorator
- func Merge(decorator Decorator, placeholders ...WC) Decorator
- func MovingAverageETA(style TimeStyle, average ewma.MovingAverage, normalizer TimeNormalizer, ...) Decorator
- func MovingAverageSpeed(unit int, format string, average ewma.MovingAverage, wcc ...WC) Decorator
- func Name(str string, wcc ...WC) Decorator
- func NewAverageETA(style TimeStyle, startTime time.Time, normalizer TimeNormalizer, wcc ...WC) Decorator
- func NewAverageSpeed(unit int, format string, startTime time.Time, wcc ...WC) Decorator
- func NewElapsed(style TimeStyle, startTime time.Time, wcc ...WC) Decorator
- func NewPercentage(format string, wcc ...WC) Decorator
- func OnComplete(decorator Decorator, message string) Decorator
- func Percentage(wcc ...WC) Decorator
- func Spinner(frames []string, wcc ...WC) Decorator
- func Total(unit int, format string, wcc ...WC) Decorator
- func TotalKibiByte(format string, wcc ...WC) Decorator
- func TotalKiloByte(format string, wcc ...WC) Decorator
- func TotalNoUnit(format string, wcc ...WC) Decorator
- type EwmaDecorator
- type ShutdownListener
- type SizeB1000
- type SizeB1024
- type Statistics
- type Synchronizer
- type TimeNormalizer
- type TimeNormalizerFunc
- type TimeStyle
- type WC
- type Wrapper
Constants ¶
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 instances of WC with sync width bit set. To be used with multiple bars only, i.e. not effective for single bar usage.
Functions ¶
func FmtAsSpeed ¶
FmtAsSpeed adds "/s" to the end of the input formatter. To be used with SizeB1000 or SizeB1024 types, for example:
fmt.Printf("%.1f", FmtAsSpeed(SizeB1024(2048)))
func NewMedian ¶
func NewMedian() ewma.MovingAverage
NewMedian is fixed last 3 samples median MovingAverage.
func NewThreadSafeMovingAverage ¶
func NewThreadSafeMovingAverage(average ewma.MovingAverage) ewma.MovingAverage
NewThreadSafeMovingAverage converts provided ewma.MovingAverage into thread safe ewma.MovingAverage.
Types ¶
type AverageDecorator ¶
AverageDecorator interface. Average decorators should implement this interface to provide start time adjustment facility, for resume-able tasks.
type Configurator ¶
Configurator interface.
type DecorFunc ¶ added in v5.1.0
type DecorFunc func(Statistics) string
DecorFunc func type. To be used with `func Any`(DecorFunc, ...WC) Decorator`.
type Decorator ¶
type Decorator interface { Configurator Synchronizer Decor(Statistics) string }
Decorator interface. Most of the time there is no need to implement this interface manually, as decor package already provides a wide range of decorators which implement this interface. If however built-in decorators don't meet your needs, you're free to implement your own one by implementing this particular interface. The easy way to go is to convert a `DecorFunc` into a `Decorator` interface by using provided `func Any(DecorFunc, ...WC) Decorator`.
func Any ¶
Any decorator displays text, that can be changed during decorator's lifetime via provided DecorFunc.
`fn` DecorFunc callback `wcc` optional WC config
func AverageETA ¶
AverageETA decorator. It's wrapper of NewAverageETA.
`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. It's a wrapper of NewAverageSpeed.
func Counters ¶
Counters decorator with dynamic unit measure adjustment.
`unit` one of [0|UnitKiB|UnitKB] zero for no unit `pairFmt` printf compatible verbs for current and total pair `wcc` optional WC config
pairFmt example if unit=UnitKB:
pairFmt="%.1f / %.1f" output: "1.0MB / 12.0MB" pairFmt="% .1f / % .1f" output: "1.0 MB / 12.0 MB" pairFmt="%d / %d" output: "1MB / 12MB" pairFmt="% d / % d" output: "1 MB / 12 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 Current ¶ added in v5.3.0
Current decorator with dynamic unit measure adjustment.
`unit` one of [0|UnitKiB|UnitKB] zero for no unit `format` printf compatible verb for Current `wcc` optional WC config
format example if unit=UnitKiB:
format="%.1f" output: "12.0MiB" format="% .1f" output: "12.0 MiB" format="%d" output: "12MiB" format="% d" output: "12 MiB"
func CurrentKibiByte ¶ added in v5.3.0
CurrentKibiByte is a wrapper around Current with predefined unit UnitKiB (bytes/1024).
func CurrentKiloByte ¶ added in v5.3.0
CurrentKiloByte is a wrapper around Current with predefined unit UnitKB (bytes/1000).
func CurrentNoUnit ¶ added in v5.3.0
CurrentNoUnit is a wrapper around Current with no unit param.
func Elapsed ¶
Elapsed decorator. It's wrapper of NewElapsed.
`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. For this decorator to work correctly you have to measure each iteration's duration and pass it to the *Bar.DecoratorEwmaUpdate(time.Duration) method after each increment.
func EwmaSpeed ¶
EwmaSpeed exponential-weighted-moving-average based speed decorator. For this decorator to work correctly you have to measure each iteration's duration and pass it to the *Bar.DecoratorEwmaUpdate(time.Duration) method after each increment.
func InvertedCurrent ¶ added in v5.3.0
InvertedCurrent decorator with dynamic unit measure adjustment.
`unit` one of [0|UnitKiB|UnitKB] zero for no unit `format` printf compatible verb for InvertedCurrent `wcc` optional WC config
format example if unit=UnitKiB:
format="%.1f" output: "12.0MiB" format="% .1f" output: "12.0 MiB" format="%d" output: "12MiB" format="% d" output: "12 MiB"
func InvertedCurrentKibiByte ¶ added in v5.3.0
InvertedCurrentKibiByte is a wrapper around InvertedCurrent with predefined unit UnitKiB (bytes/1024).
func InvertedCurrentKiloByte ¶ added in v5.3.0
InvertedCurrentKiloByte is a wrapper around InvertedCurrent with predefined unit UnitKB (bytes/1000).
func InvertedCurrentNoUnit ¶ added in v5.3.0
InvertedCurrentNoUnit is a wrapper around InvertedCurrent with no unit param.
func Merge ¶
Merge wraps its decorator argument with intention to sync width with several decorators of another bar. Visual example:
+----+--------+---------+--------+ | B1 | MERGE(D, P1, Pn) | +----+--------+---------+--------+ | B2 | D0 | D1 | Dn | +----+--------+---------+--------+
func MovingAverageETA ¶
func MovingAverageETA(style TimeStyle, average ewma.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` implementation of MovingAverage interface `normalizer` available implementations are [FixedIntervalTimeNormalizer|MaxTolerateTimeNormalizer] `wcc` optional WC config
func MovingAverageSpeed ¶
MovingAverageSpeed decorator relies on MovingAverage implementation to calculate its average.
`unit` one of [0|UnitKiB|UnitKB] zero for no unit `format` printf compatible verb for value, like "%f" or "%d" `average` MovingAverage implementation `wcc` optional WC config
format examples:
unit=UnitKiB, format="%.1f" output: "1.0MiB/s" unit=UnitKiB, format="% .1f" output: "1.0 MiB/s" unit=UnitKB, format="%.1f" output: "1.0MB/s" unit=UnitKB, format="% .1f" output: "1.0 MB/s"
func Name ¶
Name decorator displays text that is set once and can't be changed during decorator's lifetime.
`str` string to display `wcc` optional WC config
func NewAverageETA ¶
func NewAverageETA(style TimeStyle, startTime time.Time, normalizer TimeNormalizer, wcc ...WC) Decorator
NewAverageETA decorator with user provided start time.
`style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS] `startTime` start time `normalizer` available implementations are [FixedIntervalTimeNormalizer|MaxTolerateTimeNormalizer] `wcc` optional WC config
func NewAverageSpeed ¶
NewAverageSpeed decorator with dynamic unit measure adjustment and user provided start time.
`unit` one of [0|UnitKiB|UnitKB] zero for no unit `format` printf compatible verb for value, like "%f" or "%d" `startTime` start time `wcc` optional WC config
format examples:
unit=UnitKiB, format="%.1f" output: "1.0MiB/s" unit=UnitKiB, format="% .1f" output: "1.0 MiB/s" unit=UnitKB, format="%.1f" output: "1.0MB/s" unit=UnitKB, format="% .1f" output: "1.0 MB/s"
func NewElapsed ¶
NewElapsed returns elapsed time decorator.
`style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS] `startTime` start time `wcc` optional WC config
func NewPercentage ¶
NewPercentage percentage decorator with custom format string.
format examples:
format="%.1f" output: "1.0%" format="% .1f" output: "1.0 %" format="%d" output: "1%" format="% d" output: "1 %"
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 Percentage ¶
Percentage returns percentage decorator. It's a wrapper of NewPercentage.
func Spinner ¶
Spinner returns spinner decorator.
`frames` spinner frames, if nil or len==0, default is used `wcc` optional WC config
func Total ¶ added in v5.3.0
Total decorator with dynamic unit measure adjustment.
`unit` one of [0|UnitKiB|UnitKB] zero for no unit `format` printf compatible verb for Total `wcc` optional WC config
format example if unit=UnitKiB:
format="%.1f" output: "12.0MiB" format="% .1f" output: "12.0 MiB" format="%d" output: "12MiB" format="% d" output: "12 MiB"
func TotalKibiByte ¶ added in v5.3.0
TotalKibiByte is a wrapper around Total with predefined unit UnitKiB (bytes/1024).
func TotalKiloByte ¶ added in v5.3.0
TotalKiloByte is a wrapper around Total with predefined unit UnitKB (bytes/1000).
func TotalNoUnit ¶ added in v5.3.0
TotalNoUnit is a wrapper around Total with no unit param.
type EwmaDecorator ¶
EwmaDecorator interface. EWMA based decorators should implement this one.
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 SizeB1000 ¶
type SizeB1000 int64
SizeB1000 named type, which implements fmt.Formatter interface. It adjusts its value according to byte size multiple by 1000 and appends appropriate size marker (KB, MB, GB, TB).
type SizeB1024 ¶
type SizeB1024 int64
SizeB1024 named type, which implements fmt.Formatter interface. It adjusts its value according to byte size multiple by 1024 and appends appropriate size marker (KiB, MiB, GiB, TiB).
type Statistics ¶
type Statistics struct { ID int AvailableWidth int Total int64 Current int64 Refill int64 Completed bool }
Statistics consists of progress related statistics, that Decorator may need.
type Synchronizer ¶
Synchronizer interface. All decorators implement this interface implicitly. Its Sync method exposes width sync channel, if DSyncWidth bit is set.
type TimeNormalizer ¶
TimeNormalizer interface. Implementors could be passed into MovingAverageETA, in order to affect i.e. normalize its output.
func FixedIntervalTimeNormalizer ¶
func FixedIntervalTimeNormalizer(updInterval int) TimeNormalizer
FixedIntervalTimeNormalizer returns implementation of TimeNormalizer.
func MaxTolerateTimeNormalizer ¶
func MaxTolerateTimeNormalizer(maxTolerate time.Duration) TimeNormalizer
MaxTolerateTimeNormalizer returns implementation of TimeNormalizer.
type TimeNormalizerFunc ¶
TimeNormalizerFunc is function type adapter to convert function into 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, to enable width synchronization.
func (*WC) FormatMsg ¶
FormatMsg formats final message according to WC.W and WC.C. Should be called by any Decorator implementation.