AppendFunc, PrependFunc examples
Vladimir Bauer
9 years ago
| 0 | 0 | package mpb_test |
| 1 | 1 | |
| 2 | 2 | import ( |
| 3 | "fmt" | |
| 3 | 4 | "math/rand" |
| 4 | 5 | "time" |
| 5 | 6 | |
| 43 | 44 | time.Sleep(time.Millisecond * 20) |
| 44 | 45 | } |
| 45 | 46 | } |
| 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 | } | |