spinner bar example: condFillerBuilder
Vladimir Bauer
2 years ago
| 19 | 19 | total, numBars := 101, 3 |
| 20 | 20 | wg.Add(numBars) |
| 21 | 21 | |
| 22 | condFn := func(cond bool) mpb.BarFiller { | |
| 22 | condFillerBuilder := func(cond bool) mpb.BarFillerBuilder { | |
| 23 | 23 | if cond { |
| 24 | 24 | s := mpb.SpinnerStyle("∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙") |
| 25 | 25 | return s.Meta(func(s string) string { |
| 26 | 26 | return fmt.Sprint("\033[31m", s, "\033[0m") // red |
| 27 | }).Build() | |
| 27 | }) | |
| 28 | 28 | } |
| 29 | return mpb.BarStyle().Lbound("╢").Filler("▌").Tip("▌").Padding("░").Rbound("╟").Build() | |
| 29 | return mpb.BarStyle().Lbound("╢").Filler("▌").Tip("▌").Padding("░").Rbound("╟") | |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | for i := 0; i < numBars; i++ { |
| 33 | 33 | name := fmt.Sprintf("Bar#%d:", i) |
| 34 | bar := p.MustAdd(int64(total), | |
| 35 | condFn(i != 0), | |
| 34 | bar := p.New(int64(total), | |
| 35 | condFillerBuilder(i != 0), | |
| 36 | 36 | mpb.PrependDecorators( |
| 37 | 37 | // simple name decorator |
| 38 | 38 | decor.Name(name), |