Codebase list golang-github-vbauerster-mpb / a0134f9
Tweak package description Reinhard Tartler 7 years ago
1 changed file(s) with 2 addition(s) and 73 deletion(s). Raw diff Collapse all Expand all
2222 golang-github-vividcortex-ewma-dev,
2323 golang-golang-x-crypto-dev
2424 Description: multi progress bar for Go cli applications
25 Multi Progress Bar GoDoc (https://godoc.org/github.com/vbauerster/mpb)
26 Build Status (https://travis-ci.org/vbauerster/mpb) Go Report Card
27 (https://goreportcard.com/report/github.com/vbauerster/mpb)
28 .
29 mpb is a Go lib for rendering progress bars in terminal applications.
30 Features• Multiple Bars: Multiple progress bars are supported•
31 Dynamic Total: Set total while bar is running• Dynamic Add/Remove:
32 Dynamically add or remove bars• Cancellation: Cancel whole
33 rendering process• Predefined Decorators: Elapsed time, ewma
34 (https://github.com/VividCortex/ewma) based ETA, Percentage, Bytes
35 counter• Decorator's width sync: Synchronized decorator's width among
36 multiple barsUsageRendering single bar (_examples/singleBar/main.go)
37 ```go package main
38 .
39 import (
40 "math/rand" "time"
41 "github.com/vbauerster/mpb/v4" "github.com/vbauerster/mpb/v4/decor"
42 .
43 )
44 .
45 func main() {
46 // initialize progress container, with custom width p :=
47 mpb.New(mpb.WithWidth(64))
48 total := 100 name := "Single Bar:" // adding a single bar, which will
49 inherit container's width bar := p.AddBar(int64(total),
50 // set custom bar style, default one is "[=>-]"
51 mpb.BarStyle("╢▌▌░╟"), mpb.PrependDecorators(
52 // display our name with one space on the right decor.Name(name,
53 decor.WC{W: len(name) + 1, C: decor.DidentRight}), // replace ETA
54 decorator with "done" message, OnComplete event decor.OnComplete(
55 // ETA decorator with ewma age of 60, and width reservation
56 of 4 decor.EwmaETA(decor.ET_STYLE_GO, 60, decor.WC{W: 4}),
57 "done",
58 ),
59 ), mpb.AppendDecorators(decor.Percentage()),
60 ) // simulating some work max := 100 * time.Millisecond for i := 0; i <
61 total; i++ {
62 start := time.Now() time.Sleep(time.Duration(rand.Intn(10)+1) *
63 max / 10) // ewma based decorators require work duration measurement
64 bar.IncrBy(1, time.Since(start))
65 } // wait for our bar to complete and flush p.Wait()
66 .
67 } ``` Rendering multiple bars (_examples/multiBars//main.go) ```go
68 var wg sync.WaitGroup // pass &wg (optional), so p will wait for it
69 eventually p := mpb.New(mpb.WithWaitGroup(&wg)) total, numBars :=
70 100, 3 wg.Add(numBars)
71 for i := 0; i < numBars; i++ {
72 name := fmt.Sprintf("Bar#%d:", i) bar := p.AddBar(int64(total),
73 mpb.PrependDecorators(
74 // simple name decorator decor.Name(name), //
75 decor.DSyncWidth bit enables column width synchronization
76 decor.Percentage(decor.WCSyncSpace),
77 ), mpb.AppendDecorators(
78 // replace ETA decorator with "done" message, OnComplete
79 event decor.OnComplete(
80 // ETA decorator with ewma age of 60
81 decor.EwmaETA(decor.ET_STYLE_GO, 60), "done",
82 ),
83 ),
84 ) // simulating some work go func() {
85 defer wg.Done() max := 100 * time.Millisecond for i := 0; i <
86 total; i++ {
87 start := time.Now() time.Sleep(time.Duration(rand.Intn(10)+1)
88 * max / 10) // ewma based decorators require work duration
89 measurement bar.IncrBy(1, time.Since(start))
90 }
91 }()
92 } // Waiting for passed &wg and for all bars to complete and flush
93 p.Wait()
94 .
95 ``` Dynamic total (_examples/dynTotal/main.go) dynamic total
96 Complex example (_examples/complex/main.go) complex Bytes counters
97 (_examples/io/main.go) byte counters
25 mpb is a golang library for rendering progress bars in terminal
26 applications.