Codebase list golang-github-vbauerster-mpb / 5cffb9d
minor fixes Vladimir Bauer 9 years ago
4 changed file(s) with 6 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
3838 bar := p.AddBar(100).PrependName("Single Bar:", 0).AppendPercentage()
3939
4040 for i := 0; i < 100; i++ {
41 bar.Incr(1) // increment progress bar
4142 time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
42 bar.Incr(1)
4343 }
4444
4545 // Don't forget to stop mpb's rendering goroutine
6969 // if you still need p.AddBar() here and maintain ordering, use
7070 // (*mpb.Progress).BeforeRenderFunc(f mpb.BeforeRender)
7171 for i := 0; i < 100; i++ {
72 bar.Incr(1)
7273 time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
73 bar.Incr(1)
7474 }
7575 }()
7676 }
1515 func main() {
1616 decor := func(s *mpb.Statistics) string {
1717 str := fmt.Sprintf("%d/%d", s.Current, s.Total)
18 return fmt.Sprintf("%-7s", str)
18 return fmt.Sprintf("%8s", str)
1919 }
2020
2121 p := mpb.New(nil)
2626 // use bar.InProgress() bool method
2727 // for i := 0; bar.InProgress(); i += blockSize {
2828 for i := 0; i < totalItem; i += blockSize {
29 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
3029 bar.Incr(blockSize)
3130 blockSize = rand.Intn(maxBlockSize) + 1
31 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
3232 }
3333
3434 p.Stop()
2121 // if you still need p.AddBar() here and maintain ordering, use
2222 // (*mpb.Progress).BeforeRenderFunc(f mpb.BeforeRender)
2323 for i := 0; i < 100; i++ {
24 bar.Incr(1)
2425 time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
25 bar.Incr(1)
2626 }
2727 }()
2828 }
2323 bar := p.AddBar(100).PrependName("Single Bar:", 0).AppendPercentage()
2424
2525 for i := 0; i < 100; i++ {
26 bar.Incr(1) // increment progress bar
2627 time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
27 bar.Incr(1)
2828 }
2929
3030 // Don't forget to stop mpb's rendering goroutine