diff --git a/README.md b/README.md index 0798e63..573d71f 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,30 @@ * __Dynamic Addition__: Add additional progress bar at any time * __Dynamic Removal__: Remove rendering progress bar at any time * __Dynamic Sorting__: Sort bars by progression +* __Dynamic Resize: Resize bars on terminal width change * __Custom Decorator Functions__: Add custom functions around the bar along with helper functions * __Predefined Decoratros__: Elapsed time, [Ewmaest](https://github.com/dgryski/trifles/tree/master/ewmaest) based ETA, Percentage, Bytes counter ## Usage Following is the simplest use case: + +```go + name := "Single bar:" + p := mpb.New() + bar := p.AddBar(100).PrependName(name, 0).AppendPercentage() + + for i := 0; i < 100; i++ { + time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond) + bar.Incr(1) + } + + p.Stop() +``` +The source code: [example/singleBar/main.go](example/singleBar/main.go) + +However **mpb** was designed with concurrency in mind, each new bar renders in its +own goroutine. Therefore adding multiple bars is easy and safe: ```go var wg sync.WaitGroup @@ -60,6 +78,12 @@ The source code: [example/sort/main.go](example/sort/main.go) +### Resizing bars on terminal width change + +![example](example/gifs/resize.gif) + +The source code: [example/prependETA/main.go](example/prependETA/main.go) + ### Multiple io ![example](example/gifs/io-multiple.gif) diff --git a/example/gifs/resize.gif b/example/gifs/resize.gif new file mode 100644 index 0000000..78bef86 Binary files /dev/null and b/example/gifs/resize.gif differ diff --git a/example/singleBar/main.go b/example/singleBar/main.go index 18dc43b..7e230a2 100644 --- a/example/singleBar/main.go +++ b/example/singleBar/main.go @@ -8,25 +8,15 @@ "github.com/vbauerster/mpb" ) -const ( - totalItem = 100 - maxBlockSize = 10 -) - func main() { - name := "Single:" + name := "Single bar:" p := mpb.New() - bar := p.AddBar(totalItem). - PrependName(name, 0). - AppendPercentage(). - TrimRightSpace() + bar := p.AddBar(100).PrependName(name, 0).AppendPercentage() - blockSize := rand.Intn(maxBlockSize) + 1 - for i := 0; i < totalItem; i++ { - time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond))))) + for i := 0; i < 100; i++ { + time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond) bar.Incr(1) - blockSize = rand.Intn(maxBlockSize) + 1 } p.Stop()