diff --git a/README.md b/README.md index d9a762c..a98129e 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ ## Features * __Multiple Bars__: mpb can render multiple progress bars that can be tracked concurrently +* __Cancellable__: cancel rendering goroutine at any time * __Dynamic Addition__: Add additional progress bar at any time * __Dynamic Removal__: Remove rendering progress bar at any time * __Dynamic Sorting__: Sort bars by progression @@ -23,7 +24,10 @@ ```go name := "Single bar:" - p := mpb.New() + // Star mpb's rendering goroutine. + // If you don't plan to cancel, feed with nil + // otherwise provide context.Context, see cancel example + p := mpb.New(nil) bar := p.AddBar(100).PrependName(name, 0).AppendPercentage() for i := 0; i < 100; i++ { @@ -40,7 +44,7 @@ ```go var wg sync.WaitGroup - p := mpb.New() // Star mpb's rendering goroutine + p := mpb.New(nil) for i := 0; i < 3; i++ { wg.Add(1) // add wg delta name := fmt.Sprintf("Bar#%d:", i) @@ -65,6 +69,12 @@ ![example](example/gifs/simple.gif) The source code: [example/simple/main.go](example/simple/main.go) + +### Cancel + +![example](example/gifs/cancel.gif) + +The source code: [example/cancel/main.go](example/cancel/main.go) ### Removing bar diff --git a/example/gifs/cancel.gif b/example/gifs/cancel.gif new file mode 100644 index 0000000..79478fc Binary files /dev/null and b/example/gifs/cancel.gif differ diff --git a/example/gifs/remove.gif b/example/gifs/remove.gif index 56985c9..2f5edc4 100644 Binary files a/example/gifs/remove.gif and b/example/gifs/remove.gif differ diff --git a/example/gifs/simple.gif b/example/gifs/simple.gif index 919490d..aa4b350 100644 Binary files a/example/gifs/simple.gif and b/example/gifs/simple.gif differ diff --git a/example/gifs/sort.gif b/example/gifs/sort.gif index 621e3d1..227bc92 100644 Binary files a/example/gifs/sort.gif and b/example/gifs/sort.gif differ diff --git a/example/simple/main.go b/example/simple/main.go index 0c01e84..9fb6893 100644 --- a/example/simple/main.go +++ b/example/simple/main.go @@ -11,7 +11,7 @@ func main() { var wg sync.WaitGroup - p := mpb.New(nil) // Star mpb's rendering goroutine + p := mpb.New(nil) for i := 0; i < 3; i++ { wg.Add(1) // add wg delta name := fmt.Sprintf("Bar#%d:", i) diff --git a/example/singleBar/main.go b/example/singleBar/main.go index d23a8f3..bd3fae6 100644 --- a/example/singleBar/main.go +++ b/example/singleBar/main.go @@ -11,6 +11,9 @@ func main() { name := "Single bar:" + // Star mpb's rendering goroutine. + // If you don't plan to cancel, feed with nil + // otherwise provide context.Context, see cancel example p := mpb.New(nil) bar := p.AddBar(100).PrependName(name, 0).AppendPercentage()