Codebase list golang-github-vbauerster-mpb / a9f3549
gofmt Vladimir Bauer 3 years ago
12 changed file(s) with 9 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
55 // `fn` DecorFunc callback
66 //
77 // `wcc` optional WC config
8 //
98 func Any(fn DecorFunc, wcc ...WC) Decorator {
109 return &any{initWC(wcc...), fn}
1110 }
4141 // pairFmt="% .1f / % .1f" output: "1.0 MB / 12.0 MB"
4242 // pairFmt="%d / %d" output: "1MB / 12MB"
4343 // pairFmt="% d / % d" output: "1 MB / 12 MB"
44 //
4544 func Counters(unit int, pairFmt string, wcc ...WC) Decorator {
4645 producer := func(unit int, pairFmt string) DecorFunc {
4746 if pairFmt == "" {
9897 // format="% .1f" output: "12.0 MiB"
9998 // format="%d" output: "12MiB"
10099 // format="% d" output: "12 MiB"
101 //
102100 func Total(unit int, format string, wcc ...WC) Decorator {
103101 producer := func(unit int, format string) DecorFunc {
104102 if format == "" {
156154 // format="% .1f" output: "12.0 MiB"
157155 // format="%d" output: "12MiB"
158156 // format="% d" output: "12 MiB"
159 //
160157 func Current(unit int, format string, wcc ...WC) Decorator {
161158 producer := func(unit int, format string) DecorFunc {
162159 if format == "" {
214211 // format="% .1f" output: "12.0 MiB"
215212 // format="%d" output: "12MiB"
216213 // format="% d" output: "12 MiB"
217 //
218214 func InvertedCurrent(unit int, format string, wcc ...WC) Decorator {
219215 producer := func(unit int, format string) DecorFunc {
220216 if format == "" {
55 //
66 // Don't:
77 //
8 // p := mpb.New()
9 // name := decor.Name("bar")
10 // p.AddBar(100, mpb.AppendDecorators(name))
11 // p.AddBar(100, mpb.AppendDecorators(name))
8 // p := mpb.New()
9 // name := decor.Name("bar")
10 // p.AddBar(100, mpb.AppendDecorators(name))
11 // p.AddBar(100, mpb.AppendDecorators(name))
1212 //
1313 // Do:
1414 //
88 // `style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]
99 //
1010 // `wcc` optional WC config
11 //
1211 func Elapsed(style TimeStyle, wcc ...WC) Decorator {
1312 return NewElapsed(style, time.Now(), wcc...)
1413 }
2019 // `startTime` start time
2120 //
2221 // `wcc` optional WC config
23 //
2422 func NewElapsed(style TimeStyle, startTime time.Time, wcc ...WC) Decorator {
2523 var msg string
2624 producer := chooseTimeProducer(style)
4444 // `normalizer` available implementations are [FixedIntervalTimeNormalizer|MaxTolerateTimeNormalizer]
4545 //
4646 // `wcc` optional WC config
47 //
4847 func MovingAverageETA(style TimeStyle, average ewma.MovingAverage, normalizer TimeNormalizer, wcc ...WC) Decorator {
4948 d := &movingAverageETA{
5049 WC: initWC(wcc...),
8483 // `style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]
8584 //
8685 // `wcc` optional WC config
87 //
8886 func AverageETA(style TimeStyle, wcc ...WC) Decorator {
8987 return NewAverageETA(style, time.Now(), nil, wcc...)
9088 }
9896 // `normalizer` available implementations are [FixedIntervalTimeNormalizer|MaxTolerateTimeNormalizer]
9997 //
10098 // `wcc` optional WC config
101 //
10299 func NewAverageETA(style TimeStyle, startTime time.Time, normalizer TimeNormalizer, wcc ...WC) Decorator {
103100 d := &averageETA{
104101 WC: initWC(wcc...),
99 // Merge wraps its decorator argument with intention to sync width
1010 // with several decorators of another bar. Visual example:
1111 //
12 // +----+--------+---------+--------+
13 // | B1 | MERGE(D, P1, Pn) |
14 // +----+--------+---------+--------+
15 // | B2 | D0 | D1 | Dn |
16 // +----+--------+---------+--------+
17 //
12 // +----+--------+---------+--------+
13 // | B1 | MERGE(D, P1, Pn) |
14 // +----+--------+---------+--------+
15 // | B2 | D0 | D1 | Dn |
16 // +----+--------+---------+--------+
1817 func Merge(decorator Decorator, placeholders ...WC) Decorator {
1918 if decorator == nil {
2019 return nil
55 // `str` string to display
66 //
77 // `wcc` optional WC config
8 //
98 func Name(str string, wcc ...WC) Decorator {
109 return Any(func(Statistics) string { return str }, wcc...)
1110 }
66 // `decorator` Decorator to wrap
77 //
88 // `message` message to display on abort event
9 //
109 func OnAbort(decorator Decorator, message string) Decorator {
1110 if decorator == nil {
1211 return nil
55 // `decorator` Decorator to wrap
66 //
77 // `message` message to display on complete event
8 //
98 func OnComplete(decorator Decorator, message string) Decorator {
109 if decorator == nil {
1110 return nil
44 // `decorator` Decorator
55 //
66 // `cond` bool
7 //
87 func OnCondition(decorator Decorator, cond bool) Decorator {
98 return Conditional(cond, decorator, nil)
109 }
1413 // `decorator` Decorator
1514 //
1615 // `predicate` func() bool
17 //
1816 func OnPredicate(decorator Decorator, predicate func() bool) Decorator {
1917 return Predicative(predicate, decorator, nil)
2018 }
2725 // `a` Decorator
2826 //
2927 // `b` Decorator
30 //
3128 func Conditional(cond bool, a, b Decorator) Decorator {
3229 if cond {
3330 return a
4441 // `a` Decorator
4542 //
4643 // `b` Decorator
47 //
4844 func Predicative(predicate func() bool, a, b Decorator) Decorator {
4945 if predicate() {
5046 return a
4242 // format="% .1f" output: "1.0 %"
4343 // format="%d" output: "1%"
4444 // format="% d" output: "1 %"
45 //
4645 func NewPercentage(format string, wcc ...WC) Decorator {
4746 if format == "" {
4847 format = "% d"
1111 // used with SizeB1000 or SizeB1024 types, for example:
1212 //
1313 // fmt.Printf("%.1f", FmtAsSpeed(SizeB1024(2048)))
14 //
1514 func FmtAsSpeed(input fmt.Formatter) fmt.Formatter {
1615 return &speedFormatter{input}
1716 }
5655 // unit=UnitKiB, format="% .1f" output: "1.0 MiB/s"
5756 // unit=UnitKB, format="%.1f" output: "1.0MB/s"
5857 // unit=UnitKB, format="% .1f" output: "1.0 MB/s"
59 //
6058 func MovingAverageSpeed(unit int, format string, average ewma.MovingAverage, wcc ...WC) Decorator {
6159 if format == "" {
6260 format = "%.0f"
118116 // unit=UnitKiB, format="% .1f" output: "1.0 MiB/s"
119117 // unit=UnitKB, format="%.1f" output: "1.0MB/s"
120118 // unit=UnitKB, format="% .1f" output: "1.0 MB/s"
121 //
122119 func NewAverageSpeed(unit int, format string, startTime time.Time, wcc ...WC) Decorator {
123120 if format == "" {
124121 format = "%.0f"