diff --git a/bar.go b/bar.go index 5537942..01682bc 100644 --- a/bar.go +++ b/bar.go @@ -218,17 +218,21 @@ } } -// Increment is a shorthand for b.IncrBy(1) +// RefillBy fills bar with different r rune. +func (b *Bar) RefillBy(n int, r rune) { + b.operateState <- func(s *bState) { + s.refill = &refill{r, int64(n)} + } + b.IncrBy(n) +} + +// Increment is a shorthand for b.IncrBy(1). func (b *Bar) Increment() { b.IncrBy(1) } -// IncrBy increments progress bar -// -// `n` amount to increment by -// -// 'rr' optional resume rune, if provided replaces bar's fill rune for amount of n -func (b *Bar) IncrBy(n int, rr ...rune) { +// IncrBy increments progress bar by amount of n. +func (b *Bar) IncrBy(n int) { select { case b.operateState <- func(s *bState) { s.current += int64(n) @@ -241,9 +245,6 @@ s.current = s.total s.toComplete = true } - for _, r := range rr { - s.refill = &refill{r, int64(n)} - } for _, ar := range s.amountReceivers { ar.NextAmount(n) } @@ -252,7 +253,7 @@ } } -// Completed reports whether the bar is in completed state +// Completed reports whether the bar is in completed state. func (b *Bar) Completed() bool { result := make(chan bool) b.operateState <- func(s *bState) { result <- s.toComplete } diff --git a/bar_test.go b/bar_test.go index 2df7442..3f684ee 100644 --- a/bar_test.go +++ b/bar_test.go @@ -52,7 +52,7 @@ p.Wait() } -func TestBarIncrWithReFill(t *testing.T) { +func TestBarIncrRefillBy(t *testing.T) { var buf bytes.Buffer width := 100 @@ -64,7 +64,7 @@ bar := p.AddBar(int64(total), BarTrim()) - bar.IncrBy(till, refillRune) + bar.RefillBy(till, refillRune) for i := 0; i < total-till; i++ { bar.Increment()