Codebase list golang-github-vbauerster-mpb / 3f84579
AppendFunc, PrependFunc examples Vladimir Bauer 9 years ago
1 changed file(s) with 33 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
00 package mpb_test
11
22 import (
3 "fmt"
34 "math/rand"
45 "time"
56
4344 time.Sleep(time.Millisecond * 20)
4445 }
4546 }
47
48 func ExampleBar_PrependFunc() {
49 decor := func(s *mpb.Statistics) string {
50 str := fmt.Sprintf("%d/%d", s.Current, s.Total)
51 return fmt.Sprintf("%8s", str)
52 }
53
54 totalItem := 100
55 p := mpb.New(nil)
56 bar := p.AddBar(int64(totalItem)).PrependFunc(decor)
57
58 for i := 0; i < totalItem; i++ {
59 bar.Incr(1) // increment progress bar
60 time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
61 }
62 }
63
64 func ExampleBar_AppendFunc() {
65 decor := func(s *mpb.Statistics) string {
66 str := fmt.Sprintf("%d/%d", s.Current, s.Total)
67 return fmt.Sprintf("%8s", str)
68 }
69
70 totalItem := 100
71 p := mpb.New(nil)
72 bar := p.AddBar(int64(totalItem)).AppendFunc(decor)
73
74 for i := 0; i < totalItem; i++ {
75 bar.Incr(1) // increment progress bar
76 time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
77 }
78 }