IncrBy accepts optional rune
Vladimir Bauer
8 years ago
| 151 | 151 |
return proxyReader
|
| 152 | 152 |
}
|
| 153 | 153 |
|
| 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 | |
|
| 166 | 154 |
// NumOfAppenders returns current number of append decorators
|
| 167 | 155 |
func (b *Bar) NumOfAppenders() int {
|
| 168 | 156 |
result := make(chan int)
|
|
| 234 | 222 |
b.IncrBy(1)
|
| 235 | 223 |
}
|
| 236 | 224 |
|
| 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) {
|
| 239 | 231 |
select {
|
| 240 | 232 |
case b.operateState <- func(s *bState) {
|
| 241 | 233 |
s.current += int64(n)
|
|
| 247 | 239 |
} else if s.current >= s.total {
|
| 248 | 240 |
s.current = s.total
|
| 249 | 241 |
s.toComplete = true
|
|
242 |
}
|
|
243 |
for _, r := range rr {
|
|
244 |
s.refill = &refill{r, int64(n)}
|
| 250 | 245 |
}
|
| 251 | 246 |
for _, ar := range s.amountReceivers {
|
| 252 | 247 |
ar.NextAmount(n)
|
| 59 | 59 |
|
| 60 | 60 |
total := 100
|
| 61 | 61 |
till := 30
|
| 62 | |
refillChar := '+'
|
|
62 |
refillRune := '+'
|
| 63 | 63 |
|
| 64 | 64 |
bar := p.AddBar(int64(total), BarTrim())
|
| 65 | 65 |
|
| 66 | |
bar.ResumeFill(refillChar, int64(till))
|
|
66 |
bar.IncrBy(till, refillRune)
|
| 67 | 67 |
|
| 68 | |
for i := 0; i < total; i++ {
|
|
68 |
for i := 0; i < total-till; i++ {
|
| 69 | 69 |
bar.Increment()
|
| 70 | 70 |
time.Sleep(10 * time.Millisecond)
|
| 71 | 71 |
}
|
|
| 73 | 73 |
p.Wait()
|
| 74 | 74 |
|
| 75 | 75 |
wantBar := fmt.Sprintf("[%s%s]",
|
| 76 | |
strings.Repeat(string(refillChar), till-1),
|
|
76 |
strings.Repeat(string(refillRune), till-1),
|
| 77 | 77 |
strings.Repeat("=", total-till-1))
|
| 78 | 78 |
|
| 79 | 79 |
if !strings.Contains(buf.String(), wantBar) {
|