Codebase list golang-github-vbauerster-mpb / bedcaf1
RefillBy Vladimir Bauer 8 years ago
2 changed file(s) with 14 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
217217 }
218218 }
219219
220 // Increment is a shorthand for b.IncrBy(1)
220 // RefillBy fills bar with different r rune.
221 func (b *Bar) RefillBy(n int, r rune) {
222 b.operateState <- func(s *bState) {
223 s.refill = &refill{r, int64(n)}
224 }
225 b.IncrBy(n)
226 }
227
228 // Increment is a shorthand for b.IncrBy(1).
221229 func (b *Bar) Increment() {
222230 b.IncrBy(1)
223231 }
224232
225 // IncrBy increments progress bar
226 //
227 // `n` amount to increment by
228 //
229 // 'rr' optional resume rune, if provided replaces bar's fill rune for amount of n
230 func (b *Bar) IncrBy(n int, rr ...rune) {
233 // IncrBy increments progress bar by amount of n.
234 func (b *Bar) IncrBy(n int) {
231235 select {
232236 case b.operateState <- func(s *bState) {
233237 s.current += int64(n)
240244 s.current = s.total
241245 s.toComplete = true
242246 }
243 for _, r := range rr {
244 s.refill = &refill{r, int64(n)}
245 }
246247 for _, ar := range s.amountReceivers {
247248 ar.NextAmount(n)
248249 }
251252 }
252253 }
253254
254 // Completed reports whether the bar is in completed state
255 // Completed reports whether the bar is in completed state.
255256 func (b *Bar) Completed() bool {
256257 result := make(chan bool)
257258 b.operateState <- func(s *bState) { result <- s.toComplete }
5151 p.Wait()
5252 }
5353
54 func TestBarIncrWithReFill(t *testing.T) {
54 func TestBarIncrRefillBy(t *testing.T) {
5555 var buf bytes.Buffer
5656
5757 width := 100
6363
6464 bar := p.AddBar(int64(total), BarTrim())
6565
66 bar.IncrBy(till, refillRune)
66 bar.RefillBy(till, refillRune)
6767
6868 for i := 0; i < total-till; i++ {
6969 bar.Increment()