diff --git a/README.md b/README.md index da3a50e..b4c62ed 100644 --- a/README.md +++ b/README.md @@ -30,38 +30,37 @@ ```go p := mpb.New( // override default (80) width - mpb.WithWidth(100), + mpb.WithWidth(64), // override default "[=>-]" format mpb.WithFormat("╢▌▌░╟"), // override default 120ms refresh rate - mpb.WithRefreshRate(100*time.Millisecond), + mpb.WithRefreshRate(180*time.Millisecond), ) total := 100 name := "Single Bar:" - // Add a bar - // You're not limited to just a single bar, add as many as you need + // Adding a single bar bar := p.AddBar(int64(total), - // Prepending decorators mpb.PrependDecorators( - // StaticName decorator with one extra space on right + // Display our static name with one space on the right decor.StaticName(name, len(name)+1, decor.DidentRight), // ETA decorator with width reservation of 3 runes decor.ETA(3, 0), ), - // Appending decorators mpb.AppendDecorators( // Percentage decorator with width reservation of 5 runes decor.Percentage(5, 0), ), ) + // Simulating some work max := 100 * time.Millisecond for i := 0; i < total; i++ { time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + // Increment by 1 (there is bar.IncrBy(int) method, if needed) bar.Increment() } - // Wait for all bars to complete + // Wait for our bar to complete and flush p.Wait() ``` @@ -69,24 +68,24 @@ ```go var wg sync.WaitGroup p := mpb.New(mpb.WithWaitGroup(&wg)) - total := 100 - numBars := 3 + total, numBars := 100, 3 wg.Add(numBars) for i := 0; i < numBars; i++ { name := fmt.Sprintf("Bar#%d:", i) bar := p.AddBar(int64(total), mpb.PrependDecorators( - decor.StaticName(name, 0, 0), - // DSyncSpace is shortcut for DwidthSync|DextraSpace + // Display our static name with one space on the right + decor.StaticName(name, len(name)+1, decor.DidentRight), // DwidthSync bit enables same column width synchronization - // DextraSpace bit prepends decorator's output with exactly one space - decor.Percentage(3, decor.DSyncSpace), + decor.Percentage(0, decor.DwidthSync), ), mpb.AppendDecorators( - decor.ETA(3, 0), + // Replace our ETA decorator with "done!", on bar completion event + decor.OnComplete(decor.ETA(3, 0), "done!", 0, 0), ), ) + // Simulating some work go func() { defer wg.Done() max := 100 * time.Millisecond @@ -96,7 +95,8 @@ } }() } - // Wait for all bars to complete + // First wait for provided wg, + // then wait for all bars to complete and flush. p.Wait() ``` diff --git a/examples/simple/main.go b/examples/simple/main.go index c1485be..ac0c776 100644 --- a/examples/simple/main.go +++ b/examples/simple/main.go @@ -17,24 +17,24 @@ func main() { var wg sync.WaitGroup p := mpb.New(mpb.WithWaitGroup(&wg)) - total := 100 - numBars := 3 + total, numBars := 100, 3 wg.Add(numBars) for i := 0; i < numBars; i++ { name := fmt.Sprintf("Bar#%d:", i) bar := p.AddBar(int64(total), mpb.PrependDecorators( - decor.StaticName(name, 0, 0), - // DSyncSpace is shortcut for DwidthSync|DextraSpace + // Display our static name with one space on the right + decor.StaticName(name, len(name)+1, decor.DidentRight), // DwidthSync bit enables same column width synchronization - // DextraSpace bit prepends decorator's output with exactly one space - decor.Percentage(3, decor.DSyncSpace), + decor.Percentage(0, decor.DwidthSync), ), mpb.AppendDecorators( - decor.ETA(3, 0), + // Replace our ETA decorator with "done!", on bar completion event + decor.OnComplete(decor.ETA(3, 0), "done!", 0, 0), ), ) + // Simulating some work go func() { defer wg.Done() max := 100 * time.Millisecond @@ -44,6 +44,7 @@ } }() } - // Wait for all bars to complete + // First wait for provided wg, + // then wait for all bars to complete and flush. p.Wait() } diff --git a/examples/singleBar/main.go b/examples/singleBar/main.go index 062911a..50b4b44 100644 --- a/examples/singleBar/main.go +++ b/examples/singleBar/main.go @@ -11,37 +11,36 @@ func main() { p := mpb.New( // override default (80) width - mpb.WithWidth(100), + mpb.WithWidth(64), // override default "[=>-]" format mpb.WithFormat("╢▌▌░╟"), // override default 120ms refresh rate - mpb.WithRefreshRate(100*time.Millisecond), + mpb.WithRefreshRate(180*time.Millisecond), ) total := 100 name := "Single Bar:" - // Add a bar - // You're not limited to just a single bar, add as many as you need + // Adding a single bar bar := p.AddBar(int64(total), - // Prepending decorators mpb.PrependDecorators( - // StaticName decorator with one extra space on right + // Display our static name with one space on the right decor.StaticName(name, len(name)+1, decor.DidentRight), // ETA decorator with width reservation of 3 runes decor.ETA(3, 0), ), - // Appending decorators mpb.AppendDecorators( // Percentage decorator with width reservation of 5 runes decor.Percentage(5, 0), ), ) + // Simulating some work max := 100 * time.Millisecond for i := 0; i < total; i++ { time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + // Increment by 1 (there is bar.IncrBy(int) method, if needed) bar.Increment() } - // Wait for all bars to complete + // Wait for our bar to complete and flush p.Wait() }