Codebase list golang-github-vbauerster-mpb / a4cf6f1
README introduce v2 Vladimir Bauer 9 years ago
1 changed file(s) with 21 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
1515 * __Dynamic Sorting__: Sort bars as you wish
1616 * __Dynamic Resize__: Resize bars on terminal width change
1717 * __Custom Decorator Functions__: Add custom functions around the bar along with helper functions
18 * __Dynamic Decorator's Width Sync__: Sync width among decorator group (column)
1819 * __Predefined Decoratros__: Elapsed time, [Ewmaest](https://github.com/dgryski/trifles/tree/master/ewmaest) based ETA, Percentage, Bytes counter
20
21 ## Installation
22
23 To get the package, execute:
24
25 ```sh
26 go get gopkg.in/vbauerster/mpb.v1
27 ```
28
29 ```sh
30 go get gopkg.in/vbauerster/mpb.v2
31 ```
1932
2033 ## Usage
2134
2336
2437 ```go
2538 // Star mpb's rendering goroutine.
26 // If you don't plan to cancel, feed with nil
27 // otherwise provide context.Context, see cancel example
28 p := mpb.New(nil)
29 // Set custom width for every bar, which mpb will contain
39 p := mpb.New()
40 // Set custom width for every bar, which mpb will render
3041 // The default one in 70
3142 p.SetWidth(80)
3243 // Set custom format for every bar, the default one is "[=>-]"
3546 p.RefreshRate(120 * time.Millisecond)
3647
3748 // Add a bar. You're not limited to just one bar, add many if you need.
38 bar := p.AddBar(100).PrependName("Single Bar:", 0).AppendPercentage()
49 bar := p.AddBar(100).PrependName("Single Bar:", 0, 0).AppendPercentage(5, 0)
3950
4051 for i := 0; i < 100; i++ {
4152 bar.Incr(1) // increment progress bar
5869
5970 ```go
6071 var wg sync.WaitGroup
61 p := mpb.New(nil)
72 p := mpb.New()
73 wg.Add(3) // add wg delta
6274 for i := 0; i < 3; i++ {
63 wg.Add(1) // add wg delta
6475 name := fmt.Sprintf("Bar#%d:", i)
65 bar := p.AddBar(100).PrependName(name, len(name)).AppendPercentage()
76 bar := p.AddBar(100).
77 PrependName(name, len(name), 0).
78 AppendPercentage(5, 0)
6679 go func() {
6780 defer wg.Done()
6881 // you can p.AddBar() here, but ordering will be non deterministic
7689 }
7790 wg.Wait() // Wait for goroutines to finish
7891 p.Stop() // Stop mpb's rendering goroutine
79 // p.AddBar(1) // panic: you cannot reuse p, create new one!
80 fmt.Println("finish")
8192 ```
8293
8394 ![simple.gif](example/gifs/simple.gif)
118129
119130 [Here](https://github.com/vbauerster/getparty/blob/master/cmd/getparty/decorator.go) is example from [getparty](https://github.com/vbauerster/getparty) src code.
120131
121 ## Installation
122
123 ```sh
124 $ go get -u github.com/vbauerster/mpb
125 ```
126
127132 ## License
128133
129134 [MIT](https://github.com/vbauerster/mpb/blob/master/LICENSE)