simplify "complex" example
Vladimir Bauer
4 years ago
| 14 | 14 | |
| 15 | 15 | func main() { |
| 16 | 16 | numBars := 4 |
| 17 | bars := make([]*mpb.Bar, numBars) | |
| 18 | 17 | p := mpb.New() |
| 19 | 18 | |
| 20 | 19 | for i := 0; i < numBars; i++ { |
| 21 | 20 | 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, | |
| 23 | 23 | mpb.PrependDecorators( |
| 24 | 24 | decor.Name(task, decor.WC{W: len(task) + 1, C: decor.DidentRight}), |
| 25 | 25 | decor.Name("downloading", decor.WCSyncSpaceR), |
| 27 | 27 | ), |
| 28 | 28 | mpb.AppendDecorators(decor.Percentage(decor.WC{W: 5})), |
| 29 | 29 | ) |
| 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 | ) | |
| 32 | 42 | |
| 33 | for i := 0; i < numBars; i++ { | |
| 34 | afterBar := bars[i] | |
| 35 | task := fmt.Sprintf("Task#%02d:", i) | |
| 36 | 43 | 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 | } | |
| 52 | 47 | }() |
| 53 | 48 | } |
| 54 | 49 | |