poplog refactoring
Vladimir Bauer
6 years ago
| 47 | 47 | rng := rand.New(rand.NewSource(time.Now().UnixNano())) |
| 48 | 48 | max := 3000 * time.Millisecond |
| 49 | 49 | for i := 0; i < 10; i++ { |
| 50 | p.Add(0, makeLogBar(fmt.Sprintf("some log: %d", i))).SetTotal(0, true) | |
| 50 | filler := makeLogBar(fmt.Sprintf("some log: %d", i)) | |
| 51 | p.Add(0, filler, mpb.BarPriority(-1)).SetTotal(0, true) | |
| 51 | 52 | time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) |
| 52 | 53 | } |
| 53 | 54 | }() |
| 56 | 57 | p.Wait() |
| 57 | 58 | } |
| 58 | 59 | |
| 59 | func makeLogBar(msg string) mpb.FillerFunc { | |
| 60 | func makeLogBar(msg string) mpb.Filler { | |
| 60 | 61 | limit := "%%.%ds" |
| 61 | return func(w io.Writer, width int, st *decor.Statistics) { | |
| 62 | return mpb.FillerFunc(func(w io.Writer, width int, st *decor.Statistics) { | |
| 62 | 63 | fmt.Fprintf(w, fmt.Sprintf(limit, width), msg) |
| 63 | } | |
| 64 | }) | |
| 64 | 65 | } |