refactoring decoratorsOnTop
Vladimir Bauer
3 years ago
| 14 | 14 | total := 100 |
| 15 | 15 | bar := p.New(int64(total), |
| 16 | 16 | mpb.NopStyle(), // make main bar style nop, so there are just decorators |
| 17 | mpb.BarExtender(extended(mpb.BarStyle())), // extend wtih normal bar on the next line | |
| 17 | mpb.BarExtender(extended(mpb.BarStyle().Build()), false), // extend wtih normal bar on the next line | |
| 18 | 18 | mpb.PrependDecorators( |
| 19 | 19 | decor.Name("Percentage: "), |
| 20 | 20 | decor.NewPercentage("%d"), |
| 36 | 36 | p.Wait() |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | func extended(builder mpb.BarFillerBuilder) mpb.BarFiller { | |
| 40 | filler := builder.Build() | |
| 41 | return mpb.BarFillerFunc(func(w io.Writer, st decor.Statistics) { | |
| 42 | filler.Fill(w, st) | |
| 43 | w.Write([]byte("\n")) | |
| 39 | func extended(base mpb.BarFiller) mpb.BarFiller { | |
| 40 | return mpb.BarFillerFunc(func(w io.Writer, st decor.Statistics) error { | |
| 41 | err := base.Fill(w, st) | |
| 42 | if err != nil { | |
| 43 | return err | |
| 44 | } | |
| 45 | _, err = w.Write([]byte("\n")) | |
| 46 | return err | |
| 44 | 47 | }) |
| 45 | 48 | } |