readme update
Vladimir Bauer
9 years ago
| 12 | 12 | * __Dynamic Addition__: Add additional progress bar at any time |
| 13 | 13 | * __Dynamic Removal__: Remove rendering progress bar at any time |
| 14 | 14 | * __Dynamic Sorting__: Sort bars by progression |
| 15 | * __Dynamic Resize: Resize bars on terminal width change | |
| 15 | 16 | * __Custom Decorator Functions__: Add custom functions around the bar along with helper functions |
| 16 | 17 | * __Predefined Decoratros__: Elapsed time, [Ewmaest](https://github.com/dgryski/trifles/tree/master/ewmaest) based ETA, Percentage, Bytes counter |
| 17 | 18 | |
| 18 | 19 | ## Usage |
| 19 | 20 | |
| 20 | 21 | Following is the simplest use case: |
| 22 | ||
| 23 | ```go | |
| 24 | name := "Single bar:" | |
| 25 | p := mpb.New() | |
| 26 | bar := p.AddBar(100).PrependName(name, 0).AppendPercentage() | |
| 27 | ||
| 28 | for i := 0; i < 100; i++ { | |
| 29 | time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond) | |
| 30 | bar.Incr(1) | |
| 31 | } | |
| 32 | ||
| 33 | p.Stop() | |
| 34 | ``` | |
| 35 | The source code: [example/singleBar/main.go](example/singleBar/main.go) | |
| 36 | ||
| 37 | However **mpb** was designed with concurrency in mind, each new bar renders in its | |
| 38 | own goroutine. Therefore adding multiple bars is easy and safe: | |
| 21 | 39 | |
| 22 | 40 | ```go |
| 23 | 41 | var wg sync.WaitGroup |
| 59 | 77 | |
| 60 | 78 | The source code: [example/sort/main.go](example/sort/main.go) |
| 61 | 79 | |
| 80 | ### Resizing bars on terminal width change | |
| 81 | ||
| 82 |  | |
| 83 | ||
| 84 | The source code: [example/prependETA/main.go](example/prependETA/main.go) | |
| 85 | ||
| 62 | 86 | ### Multiple io |
| 63 | 87 | |
| 64 | 88 |  |
Binary diff not shown
| 7 | 7 | "github.com/vbauerster/mpb" |
| 8 | 8 | ) |
| 9 | 9 | |
| 10 | const ( | |
| 11 | totalItem = 100 | |
| 12 | maxBlockSize = 10 | |
| 13 | ) | |
| 14 | ||
| 15 | 10 | func main() { |
| 16 | 11 | |
| 17 | name := "Single:" | |
| 12 | name := "Single bar:" | |
| 18 | 13 | p := mpb.New() |
| 19 | bar := p.AddBar(totalItem). | |
| 20 | PrependName(name, 0). | |
| 21 | AppendPercentage(). | |
| 22 | TrimRightSpace() | |
| 14 | bar := p.AddBar(100).PrependName(name, 0).AppendPercentage() | |
| 23 | 15 | |
| 24 | blockSize := rand.Intn(maxBlockSize) + 1 | |
| 25 | for i := 0; i < totalItem; i++ { | |
| 26 | time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond))))) | |
| 16 | for i := 0; i < 100; i++ { | |
| 17 | time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond) | |
| 27 | 18 | bar.Incr(1) |
| 28 | blockSize = rand.Intn(maxBlockSize) + 1 | |
| 29 | 19 | } |
| 30 | 20 | |
| 31 | 21 | p.Stop() |