minor fixes
Vladimir Bauer
9 years ago
| 38 | 38 |
bar := p.AddBar(100).PrependName("Single Bar:", 0).AppendPercentage()
|
| 39 | 39 |
|
| 40 | 40 |
for i := 0; i < 100; i++ {
|
|
41 |
bar.Incr(1) // increment progress bar
|
| 41 | 42 |
time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
|
| 42 | |
bar.Incr(1)
|
| 43 | 43 |
}
|
| 44 | 44 |
|
| 45 | 45 |
// Don't forget to stop mpb's rendering goroutine
|
|
| 69 | 69 |
// if you still need p.AddBar() here and maintain ordering, use
|
| 70 | 70 |
// (*mpb.Progress).BeforeRenderFunc(f mpb.BeforeRender)
|
| 71 | 71 |
for i := 0; i < 100; i++ {
|
|
72 |
bar.Incr(1)
|
| 72 | 73 |
time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
|
| 73 | |
bar.Incr(1)
|
| 74 | 74 |
}
|
| 75 | 75 |
}()
|
| 76 | 76 |
}
|
| 15 | 15 |
func main() {
|
| 16 | 16 |
decor := func(s *mpb.Statistics) string {
|
| 17 | 17 |
str := fmt.Sprintf("%d/%d", s.Current, s.Total)
|
| 18 | |
return fmt.Sprintf("%-7s", str)
|
|
18 |
return fmt.Sprintf("%8s", str)
|
| 19 | 19 |
}
|
| 20 | 20 |
|
| 21 | 21 |
p := mpb.New(nil)
|
|
| 26 | 26 |
// use bar.InProgress() bool method
|
| 27 | 27 |
// for i := 0; bar.InProgress(); i += blockSize {
|
| 28 | 28 |
for i := 0; i < totalItem; i += blockSize {
|
| 29 | |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
| 30 | 29 |
bar.Incr(blockSize)
|
| 31 | 30 |
blockSize = rand.Intn(maxBlockSize) + 1
|
|
31 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
| 32 | 32 |
}
|
| 33 | 33 |
|
| 34 | 34 |
p.Stop()
|
| 21 | 21 |
// if you still need p.AddBar() here and maintain ordering, use
|
| 22 | 22 |
// (*mpb.Progress).BeforeRenderFunc(f mpb.BeforeRender)
|
| 23 | 23 |
for i := 0; i < 100; i++ {
|
|
24 |
bar.Incr(1)
|
| 24 | 25 |
time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
|
| 25 | |
bar.Incr(1)
|
| 26 | 26 |
}
|
| 27 | 27 |
}()
|
| 28 | 28 |
}
|
| 23 | 23 |
bar := p.AddBar(100).PrependName("Single Bar:", 0).AppendPercentage()
|
| 24 | 24 |
|
| 25 | 25 |
for i := 0; i < 100; i++ {
|
|
26 |
bar.Incr(1) // increment progress bar
|
| 26 | 27 |
time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
|
| 27 | |
bar.Incr(1)
|
| 28 | 28 |
}
|
| 29 | 29 |
|
| 30 | 30 |
// Don't forget to stop mpb's rendering goroutine
|