diff --git a/bar.go b/bar.go index 2dd5c32..5537942 100644 --- a/bar.go +++ b/bar.go @@ -152,18 +152,6 @@ return proxyReader } -// ResumeFill fills bar with different r rune, -// from 0 to till amount of progress. -func (b *Bar) ResumeFill(r rune, till int64) { - if till < 1 { - return - } - select { - case b.operateState <- func(s *bState) { s.refill = &refill{r, till} }: - case <-b.done: - } -} - // NumOfAppenders returns current number of append decorators func (b *Bar) NumOfAppenders() int { result := make(chan int) @@ -235,8 +223,12 @@ b.IncrBy(1) } -// IncrBy increments progress bar by amount of n -func (b *Bar) IncrBy(n int) { +// 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) { select { case b.operateState <- func(s *bState) { s.current += int64(n) @@ -248,6 +240,9 @@ } else if s.current >= s.total { 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) diff --git a/bar_test.go b/bar_test.go index 7933475..2df7442 100644 --- a/bar_test.go +++ b/bar_test.go @@ -60,13 +60,13 @@ total := 100 till := 30 - refillChar := '+' + refillRune := '+' bar := p.AddBar(int64(total), BarTrim()) - bar.ResumeFill(refillChar, int64(till)) + bar.IncrBy(till, refillRune) - for i := 0; i < total; i++ { + for i := 0; i < total-till; i++ { bar.Increment() time.Sleep(10 * time.Millisecond) } @@ -74,7 +74,7 @@ p.Wait() wantBar := fmt.Sprintf("[%s%s]", - strings.Repeat(string(refillChar), till-1), + strings.Repeat(string(refillRune), till-1), strings.Repeat("=", total-till-1)) if !strings.Contains(buf.String(), wantBar) {