Codebase list golang-github-vbauerster-mpb / bd8f2ad
poplog refactoring Vladimir Bauer 6 years ago
1 changed file(s) with 5 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
4747 rng := rand.New(rand.NewSource(time.Now().UnixNano()))
4848 max := 3000 * time.Millisecond
4949 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)
5152 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
5253 }
5354 }()
5657 p.Wait()
5758 }
5859
59 func makeLogBar(msg string) mpb.FillerFunc {
60 func makeLogBar(msg string) mpb.Filler {
6061 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) {
6263 fmt.Fprintf(w, fmt.Sprintf(limit, width), msg)
63 }
64 })
6465 }