Codebase list golang-github-vbauerster-mpb / 1d916c6
refactoring decoratorsOnTop Vladimir Bauer 3 years ago
1 changed file(s) with 9 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
1414 total := 100
1515 bar := p.New(int64(total),
1616 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
1818 mpb.PrependDecorators(
1919 decor.Name("Percentage: "),
2020 decor.NewPercentage("%d"),
3636 p.Wait()
3737 }
3838
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
4447 })
4548 }