Codebase list golang-github-vbauerster-mpb / b241538
simple condFillerBuilder for reverseBar example Vladimir Bauer 2 years ago
1 changed file(s) with 9 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
1616 total, numBars := 100, 3
1717 wg.Add(numBars)
1818
19 condFillerBuilder := func(cond bool) mpb.BarFillerBuilder {
20 if cond { // reverse Bar on cond
21 return mpb.BarStyle().Tip("<").Reverse()
22 }
23 return mpb.BarStyle()
24 }
25
1926 for i := 0; i < numBars; i++ {
2027 name := fmt.Sprintf("Bar#%d:", i)
21 bar := p.New(int64(total), condBuilder(i == 1),
28 bar := p.New(int64(total),
29 condFillerBuilder(i == 1),
2230 mpb.PrependDecorators(
2331 // simple name decorator
2432 decor.Name(name),
5159 // wait for passed wg and for all bars to complete and flush
5260 p.Wait()
5361 }
54
55 func condBuilder(cond bool) mpb.BarFillerBuilder {
56 return mpb.BarFillerBuilderFunc(func() mpb.BarFiller {
57 bs := mpb.BarStyle()
58 if cond {
59 // reverse Bar on cond
60 bs = bs.Tip("<").Reverse()
61 }
62 return bs.Build()
63 })
64 }