Codebase list golang-github-vbauerster-mpb / 6362e76
simplify "complex" example Vladimir Bauer 4 years ago
1 changed file(s) with 17 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
1414
1515 func main() {
1616 numBars := 4
17 bars := make([]*mpb.Bar, numBars)
1817 p := mpb.New()
1918
2019 for i := 0; i < numBars; i++ {
2120 task := fmt.Sprintf("Task#%02d:", i)
22 bars[i] = p.AddBar(rand.Int63n(201)+100,
21 queue := make([]*mpb.Bar, 2)
22 queue[0] = p.AddBar(rand.Int63n(201)+100,
2323 mpb.PrependDecorators(
2424 decor.Name(task, decor.WC{W: len(task) + 1, C: decor.DidentRight}),
2525 decor.Name("downloading", decor.WCSyncSpaceR),
2727 ),
2828 mpb.AppendDecorators(decor.Percentage(decor.WC{W: 5})),
2929 )
30 go complete(bars[i])
31 }
30 queue[1] = p.AddBar(rand.Int63n(101)+100,
31 mpb.BarQueueAfter(queue[0], false), // this bar is queued
32 mpb.BarFillerClearOnComplete(),
33 mpb.PrependDecorators(
34 decor.Name(task, decor.WC{W: len(task) + 1, C: decor.DidentRight}),
35 decor.OnComplete(decor.Name("\x1b[31minstalling\x1b[0m", decor.WCSyncSpaceR), "done!"),
36 decor.OnComplete(decor.EwmaETA(decor.ET_STYLE_MMSS, 0, decor.WCSyncWidth), ""),
37 ),
38 mpb.AppendDecorators(
39 decor.OnComplete(decor.Percentage(decor.WC{W: 5}), ""),
40 ),
41 )
3242
33 for i := 0; i < numBars; i++ {
34 afterBar := bars[i]
35 task := fmt.Sprintf("Task#%02d:", i)
3643 go func() {
37 job := "\x1b[31minstalling\x1b[0m"
38 // preparing queued bars
39 b := p.AddBar(rand.Int63n(101)+100,
40 mpb.BarQueueAfter(afterBar),
41 mpb.BarFillerClearOnComplete(),
42 mpb.PrependDecorators(
43 decor.Name(task, decor.WC{W: len(task) + 1, C: decor.DidentRight}),
44 decor.OnComplete(decor.Name(job, decor.WCSyncSpaceR), "done!"),
45 decor.OnComplete(decor.EwmaETA(decor.ET_STYLE_MMSS, 0, decor.WCSyncWidth), ""),
46 ),
47 mpb.AppendDecorators(
48 decor.OnComplete(decor.Percentage(decor.WC{W: 5}), ""),
49 ),
50 )
51 complete(b) // blocks until afterBar completes
44 for _, b := range queue {
45 complete(b)
46 }
5247 }()
5348 }
5449