README introduce v2
Vladimir Bauer
9 years ago
| 15 | 15 | * __Dynamic Sorting__: Sort bars as you wish |
| 16 | 16 | * __Dynamic Resize__: Resize bars on terminal width change |
| 17 | 17 | * __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) | |
| 18 | 19 | * __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 | ``` | |
| 19 | 32 | |
| 20 | 33 | ## Usage |
| 21 | 34 | |
| 23 | 36 | |
| 24 | 37 | ```go |
| 25 | 38 | // 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 | |
| 30 | 41 | // The default one in 70 |
| 31 | 42 | p.SetWidth(80) |
| 32 | 43 | // Set custom format for every bar, the default one is "[=>-]" |
| 35 | 46 | p.RefreshRate(120 * time.Millisecond) |
| 36 | 47 | |
| 37 | 48 | // 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) | |
| 39 | 50 | |
| 40 | 51 | for i := 0; i < 100; i++ { |
| 41 | 52 | bar.Incr(1) // increment progress bar |
| 58 | 69 | |
| 59 | 70 | ```go |
| 60 | 71 | var wg sync.WaitGroup |
| 61 | p := mpb.New(nil) | |
| 72 | p := mpb.New() | |
| 73 | wg.Add(3) // add wg delta | |
| 62 | 74 | for i := 0; i < 3; i++ { |
| 63 | wg.Add(1) // add wg delta | |
| 64 | 75 | 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) | |
| 66 | 79 | go func() { |
| 67 | 80 | defer wg.Done() |
| 68 | 81 | // you can p.AddBar() here, but ordering will be non deterministic |
| 76 | 89 | } |
| 77 | 90 | wg.Wait() // Wait for goroutines to finish |
| 78 | 91 | p.Stop() // Stop mpb's rendering goroutine |
| 79 | // p.AddBar(1) // panic: you cannot reuse p, create new one! | |
| 80 | fmt.Println("finish") | |
| 81 | 92 | ``` |
| 82 | 93 | |
| 83 | 94 |  |
| 118 | 129 | |
| 119 | 130 | [Here](https://github.com/vbauerster/getparty/blob/master/cmd/getparty/decorator.go) is example from [getparty](https://github.com/vbauerster/getparty) src code. |
| 120 | 131 | |
| 121 | ## Installation | |
| 122 | ||
| 123 | ```sh | |
| 124 | $ go get -u github.com/vbauerster/mpb | |
| 125 | ``` | |
| 126 | ||
| 127 | 132 | ## License |
| 128 | 133 | |
| 129 | 134 | [MIT](https://github.com/vbauerster/mpb/blob/master/LICENSE) |