Codebase list golang-github-vbauerster-mpb / 22ec9bb
readme examples update Vladimir Bauer 8 years ago
3 changed file(s) with 32 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
2929 ```go
3030 p := mpb.New(
3131 // override default (80) width
32 mpb.WithWidth(100),
32 mpb.WithWidth(64),
3333 // override default "[=>-]" format
3434 mpb.WithFormat("╢▌▌░╟"),
3535 // override default 120ms refresh rate
36 mpb.WithRefreshRate(100*time.Millisecond),
36 mpb.WithRefreshRate(180*time.Millisecond),
3737 )
3838
3939 total := 100
4040 name := "Single Bar:"
41 // Add a bar
42 // You're not limited to just a single bar, add as many as you need
41 // Adding a single bar
4342 bar := p.AddBar(int64(total),
44 // Prepending decorators
4543 mpb.PrependDecorators(
46 // StaticName decorator with one extra space on right
44 // Display our static name with one space on the right
4745 decor.StaticName(name, len(name)+1, decor.DidentRight),
4846 // ETA decorator with width reservation of 3 runes
4947 decor.ETA(3, 0),
5048 ),
51 // Appending decorators
5249 mpb.AppendDecorators(
5350 // Percentage decorator with width reservation of 5 runes
5451 decor.Percentage(5, 0),
5552 ),
5653 )
5754
55 // Simulating some work
5856 max := 100 * time.Millisecond
5957 for i := 0; i < total; i++ {
6058 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
59 // Increment by 1 (there is bar.IncrBy(int) method, if needed)
6160 bar.Increment()
6261 }
63 // Wait for all bars to complete
62 // Wait for our bar to complete and flush
6463 p.Wait()
6564 ```
6665
6867 ```go
6968 var wg sync.WaitGroup
7069 p := mpb.New(mpb.WithWaitGroup(&wg))
71 total := 100
72 numBars := 3
70 total, numBars := 100, 3
7371 wg.Add(numBars)
7472
7573 for i := 0; i < numBars; i++ {
7674 name := fmt.Sprintf("Bar#%d:", i)
7775 bar := p.AddBar(int64(total),
7876 mpb.PrependDecorators(
79 decor.StaticName(name, 0, 0),
80 // DSyncSpace is shortcut for DwidthSync|DextraSpace
77 // Display our static name with one space on the right
78 decor.StaticName(name, len(name)+1, decor.DidentRight),
8179 // DwidthSync bit enables same column width synchronization
82 // DextraSpace bit prepends decorator's output with exactly one space
83 decor.Percentage(3, decor.DSyncSpace),
80 decor.Percentage(0, decor.DwidthSync),
8481 ),
8582 mpb.AppendDecorators(
86 decor.ETA(3, 0),
83 // Replace our ETA decorator with "done!", on bar completion event
84 decor.OnComplete(decor.ETA(3, 0), "done!", 0, 0),
8785 ),
8886 )
87 // Simulating some work
8988 go func() {
9089 defer wg.Done()
9190 max := 100 * time.Millisecond
9594 }
9695 }()
9796 }
98 // Wait for all bars to complete
97 // First wait for provided wg,
98 // then wait for all bars to complete and flush.
9999 p.Wait()
100100 ```
101101
1616 func main() {
1717 var wg sync.WaitGroup
1818 p := mpb.New(mpb.WithWaitGroup(&wg))
19 total := 100
20 numBars := 3
19 total, numBars := 100, 3
2120 wg.Add(numBars)
2221
2322 for i := 0; i < numBars; i++ {
2423 name := fmt.Sprintf("Bar#%d:", i)
2524 bar := p.AddBar(int64(total),
2625 mpb.PrependDecorators(
27 decor.StaticName(name, 0, 0),
28 // DSyncSpace is shortcut for DwidthSync|DextraSpace
26 // Display our static name with one space on the right
27 decor.StaticName(name, len(name)+1, decor.DidentRight),
2928 // DwidthSync bit enables same column width synchronization
30 // DextraSpace bit prepends decorator's output with exactly one space
31 decor.Percentage(3, decor.DSyncSpace),
29 decor.Percentage(0, decor.DwidthSync),
3230 ),
3331 mpb.AppendDecorators(
34 decor.ETA(3, 0),
32 // Replace our ETA decorator with "done!", on bar completion event
33 decor.OnComplete(decor.ETA(3, 0), "done!", 0, 0),
3534 ),
3635 )
36 // Simulating some work
3737 go func() {
3838 defer wg.Done()
3939 max := 100 * time.Millisecond
4343 }
4444 }()
4545 }
46 // Wait for all bars to complete
46 // First wait for provided wg,
47 // then wait for all bars to complete and flush.
4748 p.Wait()
4849 }
1010 func main() {
1111 p := mpb.New(
1212 // override default (80) width
13 mpb.WithWidth(100),
13 mpb.WithWidth(64),
1414 // override default "[=>-]" format
1515 mpb.WithFormat("╢▌▌░╟"),
1616 // override default 120ms refresh rate
17 mpb.WithRefreshRate(100*time.Millisecond),
17 mpb.WithRefreshRate(180*time.Millisecond),
1818 )
1919
2020 total := 100
2121 name := "Single Bar:"
22 // Add a bar
23 // You're not limited to just a single bar, add as many as you need
22 // Adding a single bar
2423 bar := p.AddBar(int64(total),
25 // Prepending decorators
2624 mpb.PrependDecorators(
27 // StaticName decorator with one extra space on right
25 // Display our static name with one space on the right
2826 decor.StaticName(name, len(name)+1, decor.DidentRight),
2927 // ETA decorator with width reservation of 3 runes
3028 decor.ETA(3, 0),
3129 ),
32 // Appending decorators
3330 mpb.AppendDecorators(
3431 // Percentage decorator with width reservation of 5 runes
3532 decor.Percentage(5, 0),
3633 ),
3734 )
3835
36 // Simulating some work
3937 max := 100 * time.Millisecond
4038 for i := 0; i < total; i++ {
4139 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
40 // Increment by 1 (there is bar.IncrBy(int) method, if needed)
4241 bar.Increment()
4342 }
44 // Wait for all bars to complete
43 // Wait for our bar to complete and flush
4544 p.Wait()
4645 }