Codebase list golang-github-vbauerster-mpb / 2408a62
fmt godocs Vladimir Bauer 7 years ago
7 changed file(s) with 53 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
3232 shutdown chan struct{}
3333 }
3434
35 // Filler interface.
36 // Bar rednders by calling Filler's Fill method. You can literally
37 // have any bar kind, by implementing this interface and passing it
38 // to the Add method.
3539 type Filler interface {
3640 Fill(w io.Writer, width int, s *decor.Statistics)
3741 }
4646 }
4747 }
4848
49 // BarRemoveOnComplete is a flag, if set whole bar line will be removed on complete event.
50 // If both BarRemoveOnComplete and BarClearOnComplete are set, first bar section gets cleared
51 // and then whole bar line gets removed completely.
49 // BarRemoveOnComplete is a flag, if set whole bar line will be removed
50 // on complete event. If both BarRemoveOnComplete and BarClearOnComplete
51 // are set, first bar section gets cleared and then whole bar line
52 // gets removed completely.
5253 func BarRemoveOnComplete() BarOption {
5354 return func(s *bState) {
5455 s.removeOnComplete = true
5556 }
5657 }
5758
58 // BarReplaceOnComplete is indicator for delayed bar start, after the `runningBar` is complete.
59 // To achieve bar replacement effect, `runningBar` should has its `BarRemoveOnComplete` option set.
59 // BarReplaceOnComplete is indicator for delayed bar start, after the
60 // `runningBar` is complete. To achieve bar replacement effect,
61 // `runningBar` should has its `BarRemoveOnComplete` option set.
6062 func BarReplaceOnComplete(runningBar *Bar) BarOption {
6163 return func(s *bState) {
6264 s.runningBar = runningBar
6365 }
6466 }
6567
66 // BarClearOnComplete is a flag, if set will clear bar section on complete event.
67 // If you need to remove a whole bar line, refer to BarRemoveOnComplete.
68 // BarClearOnComplete is a flag, if set will clear bar section on
69 // complete event. If you need to remove a whole bar line, refer to
70 // BarRemoveOnComplete.
6871 func BarClearOnComplete() BarOption {
6972 return func(s *bState) {
7073 s.barClearOnComplete = true
7275 }
7376
7477 // BarPriority sets bar's priority.
75 // Zero is highest priority, i.e. bar will be on top.
76 // If `BarReplaceOnComplete` option is supplied, this option is ignored.
78 // Zero is highest priority, i.e. bar will be on top. If
79 // `BarReplaceOnComplete` option is supplied, this option is ignored.
7780 func BarPriority(priority int) BarOption {
7881 return func(s *bState) {
7982 s.priority = priority
8083 }
8184 }
8285
83 // BarNewLineExtend takes user defined efn, which gets called each render cycle.
84 // Any write to provided writer of efn, will appear on new line of respective bar.
86 // BarNewLineExtend takes user defined efn, which gets called each
87 // render cycle. Any write to provided writer of efn, will appear on
88 // new line of respective bar.
8589 func BarNewLineExtend(efn func(io.Writer, *decor.Statistics)) BarOption {
8690 return func(s *bState) {
8791 s.newLineExtendFn = efn
135139 return MakeFillerTypeSpecificBarOption(chk, cb)
136140 }
137141
138 // MakeFillerTypeSpecificBarOption makes BarOption specific to Filler's actual type.
139 // If you implement your own Filler, so most probably you'll need this.
140 // See BarStyle or SpinnerStyle for example.
142 // MakeFillerTypeSpecificBarOption makes BarOption specific to Filler's
143 // actual type. If you implement your own Filler, so most probably
144 // you'll need this. See BarStyle or SpinnerStyle for example.
141145 func MakeFillerTypeSpecificBarOption(
142146 typeChecker func(Filler) (interface{}, bool),
143147 cb func(interface{}),
140140 return Counters(0, pairFormat, wcc...)
141141 }
142142
143 // CountersKibiByte is a wrapper around Counters with predefined unit UnitKiB (bytes/1024).
143 // CountersKibiByte is a wrapper around Counters with predefined unit
144 // UnitKiB (bytes/1024).
144145 func CountersKibiByte(pairFormat string, wcc ...WC) Decorator {
145146 return Counters(UnitKiB, pairFormat, wcc...)
146147 }
147148
148 // CountersKiloByte is a wrapper around Counters with predefined unit UnitKB (bytes/1000).
149 // CountersKiloByte is a wrapper around Counters with predefined unit
150 // UnitKB (bytes/1000).
149151 func CountersKiloByte(pairFormat string, wcc ...WC) Decorator {
150152 return Counters(UnitKB, pairFormat, wcc...)
151153 }
4646 }
4747
4848 // Decorator interface.
49 // A decorator must implement this interface, in order to be used with mpb library.
49 // A decorator must implement this interface, in order to be used with
50 // mpb library.
5051 type Decorator interface {
5152 Decor(*Statistics) string
5253 Syncable
5354 }
5455
5556 // Syncable interface.
56 // All decorators implement this interface implicitly.
57 // Its Syncable method exposes width sync channel, if sync is enabled.
57 // All decorators implement this interface implicitly. Its Syncable
58 // method exposes width sync channel, if sync is enabled.
5859 type Syncable interface {
5960 Syncable() (bool, chan int)
6061 }
6162
6263 // OnCompleteMessenger interface.
63 // Decorators implementing this interface suppose to return provided string on complete event.
64 // Decorators implementing this interface suppose to return provided
65 // string on complete event.
6466 type OnCompleteMessenger interface {
6567 OnCompleteMessage(string)
6668 }
6769
6870 // AmountReceiver interface.
69 // If decorator needs to receive increment amount,
70 // so this is the right interface to implement.
71 // If decorator needs to receive increment amount, so this is the right
72 // interface to implement.
7173 type AmountReceiver interface {
7274 NextAmount(int, ...time.Duration)
7375 }
7476
7577 // ShutdownListener interface.
76 // If decorator needs to be notified once upon bar shutdown event,
77 // so this is the right interface to implement.
78 // If decorator needs to be notified once upon bar shutdown event, so
79 // this is the right interface to implement.
7880 type ShutdownListener interface {
7981 Shutdown()
8082 }
129131 return (wc.C & DSyncWidth) != 0, wc.wsync
130132 }
131133
132 // OnComplete returns decorator, which wraps provided decorator, with sole
133 // purpose to display provided message on complete event.
134 // OnComplete returns decorator, which wraps provided decorator, with
135 // sole purpose to display provided message on complete event.
134136 //
135137 // `decorator` Decorator to wrap
136138 //
55 "github.com/VividCortex/ewma"
66 )
77
8 // MovingAverage is the interface that computes a moving average over a time-
9 // series stream of numbers. The average may be over a window or exponentially
10 // decaying.
8 // MovingAverage is the interface that computes a moving average over
9 // a time- series stream of numbers. The average may be over a window
10 // or exponentially decaying.
1111 type MovingAverage interface {
1212 Add(float64)
1313 Value() float64
5656 s.count++
5757 }
5858
59 // NewMedianEwma is ewma based MovingAverage, which gets its values from median MovingAverage.
59 // NewMedianEwma is ewma based MovingAverage, which gets its values
60 // from median MovingAverage.
6061 func NewMedianEwma(age ...float64) MovingAverage {
6162 return &medianEwma{
6263 MovingAverage: ewma.NewMovingAverage(age...),
136136 return MovingAverageSpeed(unit, unitFormat, ewma.NewMovingAverage(age), wcc...)
137137 }
138138
139 // MovingAverageSpeed decorator relies on MovingAverage implementation to calculate its average.
139 // MovingAverageSpeed decorator relies on MovingAverage implementation
140 // to calculate its average.
140141 //
141142 // `unit` one of [0|UnitKiB|UnitKB] zero for no unit
142143 //
88 "github.com/vbauerster/mpb/cwriter"
99 )
1010
11 // ProgressOption is a function option which changes the default behavior of
12 // progress pool, if passed to mpb.New(...ProgressOption).
11 // ProgressOption is a function option which changes the default
12 // behavior of progress pool, if passed to mpb.New(...ProgressOption).
1313 type ProgressOption func(*pState)
1414
15 // WithWaitGroup provides means to have a single joint point.
16 // If *sync.WaitGroup is provided, you can safely call just p.Wait()
17 // without calling Wait() on provided *sync.WaitGroup.
18 // Makes sense when there are more than one bar to render.
15 // WithWaitGroup provides means to have a single joint point. If
16 // *sync.WaitGroup is provided, you can safely call just p.Wait()
17 // without calling Wait() on provided *sync.WaitGroup. Makes sense
18 // when there are more than one bar to render.
1919 func WithWaitGroup(wg *sync.WaitGroup) ProgressOption {
2020 return func(s *pState) {
2121 s.uwg = wg
5959 }
6060 }
6161
62 // WithShutdownNotifier provided chanel will be closed, after all bars have been rendered.
62 // WithShutdownNotifier provided chanel will be closed, after all bars
63 // have been rendered.
6364 func WithShutdownNotifier(ch chan struct{}) ProgressOption {
6465 return func(s *pState) {
6566 s.shutdownNotifier = ch