Codebase list golang-github-vbauerster-mpb / 22947a7 example / gifs / single.gif
show Format method Vladimir Bauer 9 years ago
3 changed file(s) with 19 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
2727 // If you don't plan to cancel, feed with nil
2828 // otherwise provide context.Context, see cancel example
2929 p := mpb.New(nil)
30 // Set custom format, the default one is "[=>-]"
31 p.Format("╢▌▌░╟")
32
3033 bar := p.AddBar(100).PrependName(name, 0).AppendPercentage()
3134
3235 for i := 0; i < 100; i++ {
3639
3740 p.Stop()
3841 ```
39 The source code: [example/singleBar/main.go](example/singleBar/main.go)
4042
41 However **mpb** was designed with concurrency in mind, each new bar renders in its
42 own goroutine. Therefore adding multiple bars is easy and safe:
43 Running [this](example/singleBar/main.go), will produce:
44
45 ![gif](example/gifs/single.gif)
46
47 However **mpb** was designed with concurrency in mind. Each new bar renders in its
48 own goroutine, therefore adding multiple bars is easy and safe:
4349
4450 ```go
4551 var wg sync.WaitGroup
5157 go func() {
5258 defer wg.Done()
5359 // you can p.AddBar() here, but ordering will be non deterministic
60 // if you still need p.AddBar() here and maintain ordering, use
61 // (*mpb.Progress).BeforeRenderFunc(f mpb.BeforeRender)
5462 for i := 0; i < 100; i++ {
5563 time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
5664 bar.Incr(1)
6371 fmt.Println("finish")
6472 ```
6573
66 This will produce following:
67
68 ![example](example/gifs/simple.gif)
74 ![simple.gif](example/gifs/simple.gif)
6975
7076 The source code: [example/simple/main.go](example/simple/main.go)
7177
7278 ### Cancel
7379
74 ![example](example/gifs/cancel.gif)
80 ![cancel.gif](example/gifs/cancel.gif)
7581
7682 The source code: [example/cancel/main.go](example/cancel/main.go)
7783
7884 ### Removing bar
7985
80 ![example](example/gifs/remove.gif)
86 ![remove.gif](example/gifs/remove.gif)
8187
8288 The source code: [example/remove/main.go](example/remove/main.go)
8389
8490 ### Sorting bars by progress
8591
86 ![example](example/gifs/sort.gif)
92 ![sort.gif](example/gifs/sort.gif)
8793
8894 The source code: [example/sort/main.go](example/sort/main.go)
8995
9096 ### Resizing bars on terminal width change
9197
92 ![example](example/gifs/resize.gif)
98 ![resize.gif](example/gifs/resize.gif)
9399
94100 The source code: [example/prependETA/main.go](example/prependETA/main.go)
95101
96102 ### Multiple io
97103
98 ![example](example/gifs/io-multiple.gif)
104 ![io-multiple.gif](example/gifs/io-multiple.gif)
99105
100106 The source code: [example/io/multiple/main.go](example/io/multiple/main.go)
101107
Binary diff not shown
1818 go func() {
1919 defer wg.Done()
2020 // you can p.AddBar() here, but ordering will be non deterministic
21 // if you still need p.AddBar() here and maintain ordering, use
22 // (*mpb.Progress).BeforeRenderFunc(f mpb.BeforeRender)
2123 for i := 0; i < 100; i++ {
2224 time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
2325 bar.Incr(1)