diff --git a/_examples/reverseBar/main.go b/_examples/reverseBar/main.go index 2ea06c7..216e77f 100644 --- a/_examples/reverseBar/main.go +++ b/_examples/reverseBar/main.go @@ -21,7 +21,7 @@ name := fmt.Sprintf("Bar#%d:", i) bar := p.Add(int64(total), // reverse Bar#1 - mpb.NewBarFillerRev("", func() bool { return i == 1 }), + mpb.PickBarFiller("", i == 1), mpb.PrependDecorators( // simple name decorator decor.Name(name), diff --git a/bar_filler_bar.go b/bar_filler_bar.go index 0904d17..3802c03 100644 --- a/bar_filler_bar.go +++ b/bar_filler_bar.go @@ -55,17 +55,32 @@ } // NewBarFiller returns a BarFiller implementation which renders a -// classic progress bar. To be used with *Progress.Add(...) *Bar method. +// progress bar in regular direction. If style is empty string, +// BarDefaultStyle is applied. To be used with `*Progress.Add(...) +// *Bar` method. func NewBarFiller(style string) BarFiller { - return NewBarFillerRev(style, func() bool { return false }) + return newBarFiller(style, false) } -// NewBarFillerRev same as NewBarFiller but with explicit reverse option. -func NewBarFillerRev(style string, rev func() bool) BarFiller { +// NewBarFillerRev returns a BarFiller implementation which renders a +// progress bar in reverse direction. If style is empty string, +// BarDefaultStyle is applied. To be used with `*Progress.Add(...) +// *Bar` method. +func NewBarFillerRev(style string) BarFiller { + return newBarFiller(style, true) +} + +// PickBarFiller pick between regular and reverse BarFiller implementation +// based on rev param. To be used with `*Progress.Add(...) *Bar` method. +func PickBarFiller(style string, rev bool) BarFiller { + return newBarFiller(style, rev) +} + +func newBarFiller(style string, rev bool) BarFiller { bf := &barFiller{ - reverse: rev(), format: make([][]byte, len(BarDefaultStyle)), rwidth: make([]int, len(BarDefaultStyle)), + reverse: rev, } bf.parse(BarDefaultStyle) if style != "" && style != BarDefaultStyle { diff --git a/draw_test.go b/draw_test.go index a3c194d..7efb650 100644 --- a/draw_test.go +++ b/draw_test.go @@ -367,12 +367,9 @@ } } -func newTestState(style string, reverse bool) *bState { - if style == "" { - style = DefaultBarStyle - } +func newTestState(style string, rev bool) *bState { s := &bState{ - filler: NewBarFiller(style, reverse), + filler: PickBarFiller(style, rev), bufP: new(bytes.Buffer), bufB: new(bytes.Buffer), bufA: new(bytes.Buffer),