RefillBy
Vladimir Bauer
8 years ago
| 217 | 217 |
}
|
| 218 | 218 |
}
|
| 219 | 219 |
|
| 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).
|
| 221 | 229 |
func (b *Bar) Increment() {
|
| 222 | 230 |
b.IncrBy(1)
|
| 223 | 231 |
}
|
| 224 | 232 |
|
| 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) {
|
| 231 | 235 |
select {
|
| 232 | 236 |
case b.operateState <- func(s *bState) {
|
| 233 | 237 |
s.current += int64(n)
|
|
| 240 | 244 |
s.current = s.total
|
| 241 | 245 |
s.toComplete = true
|
| 242 | 246 |
}
|
| 243 | |
for _, r := range rr {
|
| 244 | |
s.refill = &refill{r, int64(n)}
|
| 245 | |
}
|
| 246 | 247 |
for _, ar := range s.amountReceivers {
|
| 247 | 248 |
ar.NextAmount(n)
|
| 248 | 249 |
}
|
|
| 251 | 252 |
}
|
| 252 | 253 |
}
|
| 253 | 254 |
|
| 254 | |
// Completed reports whether the bar is in completed state
|
|
255 |
// Completed reports whether the bar is in completed state.
|
| 255 | 256 |
func (b *Bar) Completed() bool {
|
| 256 | 257 |
result := make(chan bool)
|
| 257 | 258 |
b.operateState <- func(s *bState) { result <- s.toComplete }
|
| 51 | 51 |
p.Wait()
|
| 52 | 52 |
}
|
| 53 | 53 |
|
| 54 | |
func TestBarIncrWithReFill(t *testing.T) {
|
|
54 |
func TestBarIncrRefillBy(t *testing.T) {
|
| 55 | 55 |
var buf bytes.Buffer
|
| 56 | 56 |
|
| 57 | 57 |
width := 100
|
|
| 63 | 63 |
|
| 64 | 64 |
bar := p.AddBar(int64(total), BarTrim())
|
| 65 | 65 |
|
| 66 | |
bar.IncrBy(till, refillRune)
|
|
66 |
bar.RefillBy(till, refillRune)
|
| 67 | 67 |
|
| 68 | 68 |
for i := 0; i < total-till; i++ {
|
| 69 | 69 |
bar.Increment()
|