Codebase list golang-github-vbauerster-mpb / ddb88cf
IncrBy accepts optional rune Vladimir Bauer 8 years ago
2 changed file(s) with 13 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
151151 return proxyReader
152152 }
153153
154 // ResumeFill fills bar with different r rune,
155 // from 0 to till amount of progress.
156 func (b *Bar) ResumeFill(r rune, till int64) {
157 if till < 1 {
158 return
159 }
160 select {
161 case b.operateState <- func(s *bState) { s.refill = &refill{r, till} }:
162 case <-b.done:
163 }
164 }
165
166154 // NumOfAppenders returns current number of append decorators
167155 func (b *Bar) NumOfAppenders() int {
168156 result := make(chan int)
234222 b.IncrBy(1)
235223 }
236224
237 // IncrBy increments progress bar by amount of n
238 func (b *Bar) IncrBy(n int) {
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) {
239231 select {
240232 case b.operateState <- func(s *bState) {
241233 s.current += int64(n)
247239 } else if s.current >= s.total {
248240 s.current = s.total
249241 s.toComplete = true
242 }
243 for _, r := range rr {
244 s.refill = &refill{r, int64(n)}
250245 }
251246 for _, ar := range s.amountReceivers {
252247 ar.NextAmount(n)
5959
6060 total := 100
6161 till := 30
62 refillChar := '+'
62 refillRune := '+'
6363
6464 bar := p.AddBar(int64(total), BarTrim())
6565
66 bar.ResumeFill(refillChar, int64(till))
66 bar.IncrBy(till, refillRune)
6767
68 for i := 0; i < total; i++ {
68 for i := 0; i < total-till; i++ {
6969 bar.Increment()
7070 time.Sleep(10 * time.Millisecond)
7171 }
7373 p.Wait()
7474
7575 wantBar := fmt.Sprintf("[%s%s]",
76 strings.Repeat(string(refillChar), till-1),
76 strings.Repeat(string(refillRune), till-1),
7777 strings.Repeat("=", total-till-1))
7878
7979 if !strings.Contains(buf.String(), wantBar) {