Codebase list golang-github-vbauerster-mpb / 1dd7643
fix examples Vladimir Bauer 6 years ago
5 changed file(s) with 7 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
1818
1919 for i := 0; i < numBars; i++ {
2020 name := fmt.Sprintf("Bar#%d:", i)
21 efn := func(w io.Writer, width int, s *decor.Statistics) {
21 efn := func(w io.Writer, width int, s decor.Statistics) {
2222 if s.Completed {
2323 fmt.Fprintf(w, "Bar id: %d has been completed\n", s.ID)
2424 }
6262
6363 func newVariadicSpinner(wc decor.WC) decor.Decorator {
6464 spinner := decor.Spinner(nil)
65 f := func(s *decor.Statistics) string {
65 f := func(s decor.Statistics) string {
6666 return strings.Repeat(spinner.Decor(s), int(s.Current/3))
6767 }
6868 return decor.Any(f, wc)
3434 }
3535
3636 func panicDecorator(name, panicMsg string) decor.Decorator {
37 return decor.Any(func(s *decor.Statistics) string {
37 return decor.Any(func(s decor.Statistics) string {
3838 if s.ID == 1 && s.Current >= 42 {
3939 panic(panicMsg)
4040 }
6363
6464 func makeLogBar(msg string) mpb.BarFiller {
6565 limit := "%%.%ds"
66 return mpb.BarFillerFunc(func(w io.Writer, width int, st *decor.Statistics) {
66 return mpb.BarFillerFunc(func(w io.Writer, width int, st decor.Statistics) {
6767 fmt.Fprintf(w, fmt.Sprintf(limit, width), msg)
6868 })
6969 }
8888 base := mpb.NewBarFiller(mpb.DefaultBarStyle, false)
8989 nextCh := make(chan struct{}, 1)
9090 var msg *string
91 filler := mpb.BarFillerFunc(func(w io.Writer, width int, st *decor.Statistics) {
91 filler := mpb.BarFillerFunc(func(w io.Writer, width int, st decor.Statistics) {
9292 select {
9393 case m := <-ch:
9494 defer func() {
116116
117117 func newCustomPercentage(ch <-chan struct{}) decor.Decorator {
118118 base := decor.Percentage()
119 f := func(s *decor.Statistics) string {
119 fn := func(s decor.Statistics) string {
120120 select {
121121 case <-ch:
122122 return ""
124124 return base.Decor(s)
125125 }
126126 }
127 return decor.Any(f)
127 return decor.Any(fn)
128128 }