Readme update
Vladimir Bauer
8 years ago
| 12 | 12 | * __Dynamic Total__: [Set total](https://github.com/vbauerster/mpb/issues/9#issuecomment-344448984) while bar is running |
| 13 | 13 | * __Dynamic Add/Remove__: Dynamically add or remove bars |
| 14 | 14 | * __Cancellation__: Cancel whole rendering process |
| 15 | * __Predefined Decorators__: Elapsed time, [Ewmaest](https://github.com/dgryski/trifles/tree/master/ewmaest) based ETA, Percentage, Bytes counter | |
| 15 | * __Predefined Decorators__: Elapsed time, [ewma](https://github.com/VividCortex/ewma) based ETA, Percentage, Bytes counter | |
| 16 | 16 | * __Decorator's width sync__: Synchronized decorator's width among multiple bars |
| 17 | 17 | |
| 18 | 18 | ## Installation |
| 38 | 38 | |
| 39 | 39 | total := 100 |
| 40 | 40 | name := "Single Bar:" |
| 41 | startBlock := make(chan time.Time) | |
| 41 | 42 | // adding a single bar |
| 42 | 43 | bar := p.AddBar(int64(total), |
| 43 | 44 | mpb.PrependDecorators( |
| 44 | // Display our static name with one space on the right | |
| 45 | decor.StaticName(name, len(name)+1, decor.DidentRight), | |
| 46 | // ETA decorator with width reservation of 3 runes | |
| 47 | decor.ETA(3, 0), | |
| 45 | // Display our name with one space on the right | |
| 46 | decor.Name(name, decor.WC{W: len(name) + 1, C: decor.DidentRight}), | |
| 47 | // Replace ETA decorator with message, OnComplete event | |
| 48 | decor.OnComplete( | |
| 49 | // ETA decorator with default eta age, and width reservation of 4 | |
| 50 | decor.ETA(decor.ET_STYLE_GO, 0, startBlock, decor.WC{W: 4}), | |
| 51 | "done", | |
| 52 | ), | |
| 48 | 53 | ), |
| 49 | 54 | mpb.AppendDecorators( |
| 50 | // Percentage decorator with width reservation of 5 runes | |
| 51 | decor.Percentage(5, 0), | |
| 55 | decor.Percentage(), | |
| 52 | 56 | ), |
| 53 | 57 | ) |
| 54 | 58 | |
| 55 | 59 | // simulating some work |
| 56 | 60 | max := 100 * time.Millisecond |
| 57 | 61 | for i := 0; i < total; i++ { |
| 58 | bar.StartBlock() // optional call, required for ETA | |
| 62 | // update start block time, required for ETA calculation | |
| 63 | startBlock <- time.Now() | |
| 59 | 64 | time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) |
| 60 | // increment by 1 (there is bar.IncrBy(int) method, if needed) | |
| 65 | // Increment by 1 (there is bar.IncrBy(int) method, if needed) | |
| 61 | 66 | bar.Increment() |
| 62 | 67 | } |
| 63 | 68 | // wait for our bar to complete and flush |
| 73 | 78 | |
| 74 | 79 | for i := 0; i < numBars; i++ { |
| 75 | 80 | name := fmt.Sprintf("Bar#%d:", i) |
| 81 | startBlock := make(chan time.Time) | |
| 76 | 82 | bar := p.AddBar(int64(total), |
| 77 | 83 | mpb.PrependDecorators( |
| 78 | // Display our static name with one space on the right | |
| 79 | decor.StaticName(name, len(name)+1, decor.DidentRight), | |
| 80 | // DwidthSync bit enables same column width synchronization | |
| 81 | decor.Percentage(0, decor.DwidthSync), | |
| 84 | // Display our name with one space on the right | |
| 85 | decor.Name(name, decor.WC{W: len(name) + 1, C: decor.DidentRight}), | |
| 86 | // decor.DSyncWidth bit enables same column width synchronization | |
| 87 | decor.Percentage(decor.WCSyncWidth), | |
| 82 | 88 | ), |
| 83 | 89 | mpb.AppendDecorators( |
| 84 | // Replace our ETA decorator with "done!", on bar completion event | |
| 85 | decor.OnComplete(decor.ETA(3, 0), "done!", 0, 0), | |
| 90 | // Replace ETA decorator with message, OnComplete event | |
| 91 | decor.OnComplete( | |
| 92 | // ETA decorator with default eta age, and width reservation of 3 | |
| 93 | decor.ETA(decor.ET_STYLE_GO, 0, startBlock, decor.WC{W: 3}), | |
| 94 | "done!", | |
| 95 | ), | |
| 86 | 96 | ), |
| 87 | 97 | ) |
| 88 | 98 | // simulating some work |
| 90 | 100 | defer wg.Done() |
| 91 | 101 | max := 100 * time.Millisecond |
| 92 | 102 | for i := 0; i < total; i++ { |
| 93 | bar.StartBlock() | |
| 103 | startBlock <- time.Now() | |
| 94 | 104 | time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) |
| 95 | 105 | bar.Increment() |
| 96 | 106 | } |
| 97 | 107 | }() |
| 98 | 108 | } |
| 99 | // first wait for provided wg, then | |
| 100 | 109 | // wait for all bars to complete and flush |
| 101 | 110 | p.Wait() |
| 102 | 111 | ``` |