Codebase list golang-github-vbauerster-mpb / 6f4a221
refactoring: NewBarFiller and NewBarFillerRev Vladimir Bauer 5 years ago
3 changed file(s) with 12 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
1414 //
1515 // Default implementations can be obtained via:
1616 //
17 // func NewBarFiller(style string, reverse bool) BarFiller
17 // func NewBarFiller(style string) BarFiller
1818 // func NewSpinnerFiller(style []string, alignment SpinnerAlignment) BarFiller
1919 //
2020 type BarFiller interface {
5353 count int
5454 }
5555
56 // NewBarFiller constucts mpb.BarFiller, to be used with *Progress.Add(...) *Bar method.
57 func NewBarFiller(style string, reverse bool) BarFiller {
56 // NewBarFiller returns a BarFiller implementation which renders a
57 // classic progress bar. To be used with *Progress.Add(...) *Bar method.
58 func NewBarFiller(style string) BarFiller {
59 return NewBarFillerRev(style, func() bool { return false })
60 }
61
62 // NewBarFillerRev same as NewBarFiller but with explicit reverse option.
63 func NewBarFillerRev(style string, rev func() bool) BarFiller {
5864 bf := &barFiller{
5965 format: make([][]byte, len(DefaultBarStyle)),
6066 rwidth: make([]int, len(DefaultBarStyle)),
61 reverse: reverse,
67 reverse: rev(),
6268 }
6369 bf.parse(DefaultBarStyle)
64 if style != DefaultBarStyle {
70 if style != "" && style != DefaultBarStyle {
6571 bf.parse(style)
6672 }
6773 return bf
9696
9797 // AddBar creates a new progress bar and adds it to the rendering queue.
9898 func (p *Progress) AddBar(total int64, options ...BarOption) *Bar {
99 return p.Add(total, NewBarFiller(DefaultBarStyle, false), options...)
99 return p.Add(total, NewBarFiller(DefaultBarStyle), options...)
100100 }
101101
102102 // AddSpinner creates a new spinner bar and adds it to the rendering queue.