Codebase list golang-github-vbauerster-mpb / 4b77e73
tabs to spaces Vladimir Bauer 8 years ago
1 changed file(s) with 74 addition(s) and 74 deletion(s). Raw diff Collapse all Expand all
2727
2828 #### [Rendering single bar](examples/singleBar/main.go)
2929 ```go
30 p := mpb.New(
31 // override default (80) width
32 mpb.WithWidth(64),
33 // override default "[=>-]" format
34 mpb.WithFormat("╢▌▌░╟"),
35 // override default 120ms refresh rate
36 mpb.WithRefreshRate(180*time.Millisecond),
37 )
30 p := mpb.New(
31 // override default (80) width
32 mpb.WithWidth(64),
33 // override default "[=>-]" format
34 mpb.WithFormat("╢▌▌░╟"),
35 // override default 120ms refresh rate
36 mpb.WithRefreshRate(180*time.Millisecond),
37 )
3838
39 total := 100
40 name := "Single Bar:"
41 startBlock := make(chan time.Time)
42 // adding a single bar
43 bar := p.AddBar(int64(total),
44 mpb.PrependDecorators(
45 // Display our name with one space on the right
46 decor.Name(name, decor.WC{W: len(name) + 1, C: decor.DidentRight}),
47 // Replace ETA decorator with message, OnComplete event
48 decor.OnComplete(
49 // ETA decorator with default eta age, and width reservation of 4
50 decor.ETA(decor.ET_STYLE_GO, 0, startBlock, decor.WC{W: 4}),
51 "done",
52 ),
53 ),
54 mpb.AppendDecorators(
55 decor.Percentage(),
56 ),
57 )
39 total := 100
40 name := "Single Bar:"
41 startBlock := make(chan time.Time)
42 // adding a single bar
43 bar := p.AddBar(int64(total),
44 mpb.PrependDecorators(
45 // Display our name with one space on the right
46 decor.Name(name, decor.WC{W: len(name) + 1, C: decor.DidentRight}),
47 // Replace ETA decorator with message, OnComplete event
48 decor.OnComplete(
49 // ETA decorator with default eta age, and width reservation of 4
50 decor.ETA(decor.ET_STYLE_GO, 0, startBlock, decor.WC{W: 4}),
51 "done",
52 ),
53 ),
54 mpb.AppendDecorators(
55 decor.Percentage(),
56 ),
57 )
5858
59 // simulating some work
60 max := 100 * time.Millisecond
61 for i := 0; i < total; i++ {
62 // update start block time, required for ETA calculation
63 startBlock <- time.Now()
64 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
65 // Increment by 1 (there is bar.IncrBy(int) method, if needed)
66 bar.Increment()
67 }
68 // wait for our bar to complete and flush
69 p.Wait()
59 // simulating some work
60 max := 100 * time.Millisecond
61 for i := 0; i < total; i++ {
62 // update start block time, required for ETA calculation
63 startBlock <- time.Now()
64 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
65 // Increment by 1 (there is bar.IncrBy(int) method, if needed)
66 bar.Increment()
67 }
68 // wait for our bar to complete and flush
69 p.Wait()
7070 ```
7171
7272 #### [Rendering multiple bars](examples/simple/main.go)
7373 ```go
74 var wg sync.WaitGroup
75 p := mpb.New(mpb.WithWaitGroup(&wg))
76 total, numBars := 100, 3
77 wg.Add(numBars)
74 var wg sync.WaitGroup
75 p := mpb.New(mpb.WithWaitGroup(&wg))
76 total, numBars := 100, 3
77 wg.Add(numBars)
7878
79 for i := 0; i < numBars; i++ {
80 name := fmt.Sprintf("Bar#%d:", i)
81 startBlock := make(chan time.Time)
82 bar := p.AddBar(int64(total),
83 mpb.PrependDecorators(
84 // Display our name with one space on the right
85 decor.Name(name, decor.WC{W: len(name) + 1, C: decor.DidentRight}),
86 // decor.DSyncWidth bit enables same column width synchronization
87 decor.Percentage(decor.WCSyncWidth),
88 ),
89 mpb.AppendDecorators(
90 // Replace ETA decorator with message, OnComplete event
91 decor.OnComplete(
92 // ETA decorator with default eta age, and width reservation of 3
93 decor.ETA(decor.ET_STYLE_GO, 0, startBlock, decor.WC{W: 3}),
94 "done!",
95 ),
96 ),
97 )
98 // simulating some work
99 go func() {
100 defer wg.Done()
101 max := 100 * time.Millisecond
102 for i := 0; i < total; i++ {
103 startBlock <- time.Now()
104 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
105 bar.Increment()
106 }
107 }()
108 }
109 // wait for all bars to complete and flush
110 p.Wait()
79 for i := 0; i < numBars; i++ {
80 name := fmt.Sprintf("Bar#%d:", i)
81 startBlock := make(chan time.Time)
82 bar := p.AddBar(int64(total),
83 mpb.PrependDecorators(
84 // Display our name with one space on the right
85 decor.Name(name, decor.WC{W: len(name) + 1, C: decor.DidentRight}),
86 // decor.DSyncWidth bit enables same column width synchronization
87 decor.Percentage(decor.WCSyncWidth),
88 ),
89 mpb.AppendDecorators(
90 // Replace ETA decorator with message, OnComplete event
91 decor.OnComplete(
92 // ETA decorator with default eta age, and width reservation of 3
93 decor.ETA(decor.ET_STYLE_GO, 0, startBlock, decor.WC{W: 3}),
94 "done!",
95 ),
96 ),
97 )
98 // simulating some work
99 go func() {
100 defer wg.Done()
101 max := 100 * time.Millisecond
102 for i := 0; i < total; i++ {
103 startBlock <- time.Now()
104 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
105 bar.Increment()
106 }
107 }()
108 }
109 // wait for all bars to complete and flush
110 p.Wait()
111111 ```
112112
113113 #### [Dynamic total](examples/dynTotal/main.go)