fix examples
Vladimir Bauer
6 years ago
| 18 | 18 |
|
| 19 | 19 |
for i := 0; i < numBars; i++ {
|
| 20 | 20 |
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) {
|
| 22 | 22 |
if s.Completed {
|
| 23 | 23 |
fmt.Fprintf(w, "Bar id: %d has been completed\n", s.ID)
|
| 24 | 24 |
}
|
| 62 | 62 |
|
| 63 | 63 |
func newVariadicSpinner(wc decor.WC) decor.Decorator {
|
| 64 | 64 |
spinner := decor.Spinner(nil)
|
| 65 | |
f := func(s *decor.Statistics) string {
|
|
65 |
f := func(s decor.Statistics) string {
|
| 66 | 66 |
return strings.Repeat(spinner.Decor(s), int(s.Current/3))
|
| 67 | 67 |
}
|
| 68 | 68 |
return decor.Any(f, wc)
|
| 34 | 34 |
}
|
| 35 | 35 |
|
| 36 | 36 |
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 {
|
| 38 | 38 |
if s.ID == 1 && s.Current >= 42 {
|
| 39 | 39 |
panic(panicMsg)
|
| 40 | 40 |
}
|
| 63 | 63 |
|
| 64 | 64 |
func makeLogBar(msg string) mpb.BarFiller {
|
| 65 | 65 |
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) {
|
| 67 | 67 |
fmt.Fprintf(w, fmt.Sprintf(limit, width), msg)
|
| 68 | 68 |
})
|
| 69 | 69 |
}
|
| 88 | 88 |
base := mpb.NewBarFiller(mpb.DefaultBarStyle, false)
|
| 89 | 89 |
nextCh := make(chan struct{}, 1)
|
| 90 | 90 |
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) {
|
| 92 | 92 |
select {
|
| 93 | 93 |
case m := <-ch:
|
| 94 | 94 |
defer func() {
|
|
| 116 | 116 |
|
| 117 | 117 |
func newCustomPercentage(ch <-chan struct{}) decor.Decorator {
|
| 118 | 118 |
base := decor.Percentage()
|
| 119 | |
f := func(s *decor.Statistics) string {
|
|
119 |
fn := func(s decor.Statistics) string {
|
| 120 | 120 |
select {
|
| 121 | 121 |
case <-ch:
|
| 122 | 122 |
return ""
|
|
| 124 | 124 |
return base.Decor(s)
|
| 125 | 125 |
}
|
| 126 | 126 |
}
|
| 127 | |
return decor.Any(f)
|
|
127 |
return decor.Any(fn)
|
| 128 | 128 |
}
|