Codebase list golang-github-vbauerster-mpb / cee2d6e
PickBarFiller Vladimir Bauer 5 years ago
3 changed file(s) with 23 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
2020 name := fmt.Sprintf("Bar#%d:", i)
2121 bar := p.Add(int64(total),
2222 // reverse Bar#1
23 mpb.NewBarFillerRev("", func() bool { return i == 1 }),
23 mpb.PickBarFiller("", i == 1),
2424 mpb.PrependDecorators(
2525 // simple name decorator
2626 decor.Name(name),
5454 }
5555
5656 // NewBarFiller returns a BarFiller implementation which renders a
57 // classic progress bar. To be used with *Progress.Add(...) *Bar method.
57 // progress bar in regular direction. If style is empty string,
58 // BarDefaultStyle is applied. To be used with `*Progress.Add(...)
59 // *Bar` method.
5860 func NewBarFiller(style string) BarFiller {
59 return NewBarFillerRev(style, func() bool { return false })
61 return newBarFiller(style, false)
6062 }
6163
62 // NewBarFillerRev same as NewBarFiller but with explicit reverse option.
63 func NewBarFillerRev(style string, rev func() bool) BarFiller {
64 // NewBarFillerRev returns a BarFiller implementation which renders a
65 // progress bar in reverse direction. If style is empty string,
66 // BarDefaultStyle is applied. To be used with `*Progress.Add(...)
67 // *Bar` method.
68 func NewBarFillerRev(style string) BarFiller {
69 return newBarFiller(style, true)
70 }
71
72 // PickBarFiller pick between regular and reverse BarFiller implementation
73 // based on rev param. To be used with `*Progress.Add(...) *Bar` method.
74 func PickBarFiller(style string, rev bool) BarFiller {
75 return newBarFiller(style, rev)
76 }
77
78 func newBarFiller(style string, rev bool) BarFiller {
6479 bf := &barFiller{
65 reverse: rev(),
6680 format: make([][]byte, len(BarDefaultStyle)),
6781 rwidth: make([]int, len(BarDefaultStyle)),
82 reverse: rev,
6883 }
6984 bf.parse(BarDefaultStyle)
7085 if style != "" && style != BarDefaultStyle {
366366 }
367367 }
368368
369 func newTestState(style string, reverse bool) *bState {
370 if style == "" {
371 style = DefaultBarStyle
372 }
369 func newTestState(style string, rev bool) *bState {
373370 s := &bState{
374 filler: NewBarFiller(style, reverse),
371 filler: PickBarFiller(style, rev),
375372 bufP: new(bytes.Buffer),
376373 bufB: new(bytes.Buffer),
377374 bufA: new(bytes.Buffer),