Codebase list golang-github-vbauerster-mpb / 9458362
examples update Vladimir Bauer 9 years ago
3 changed file(s) with 18 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
4040 }
4141
4242 func (b *Bar) PrependETA(padding int) *Bar {
43 layout := "ETA%" + strconv.Itoa(padding) + "s"
43 layout := "ETA% " + strconv.Itoa(padding) + "s"
4444 b.PrependFunc(func(s *Statistics) string {
4545 return fmt.Sprintf(layout, time.Duration(s.Eta().Seconds())*time.Second)
4646 })
4747 return b
4848 }
4949
50 func (b *Bar) AppendETA() *Bar {
50 func (b *Bar) AppendETA(padding int) *Bar {
51 layout := "ETA% " + strconv.Itoa(padding) + "s"
5152 b.AppendFunc(func(s *Statistics) string {
52 return fmt.Sprintf("ETA %s", time.Duration(s.Eta().Seconds())*time.Second)
53 return fmt.Sprintf(layout, time.Duration(s.Eta().Seconds())*time.Second)
5354 })
5455 return b
5556 }
5959
6060 // create bar with appropriate decorators
6161 bar := p.AddBar(int(size)).
62 PrependName(name, len(name)).
6263 PrependCounters(mpb.UnitBytes, 20).
63 PrependName(name, len(name)).
64 AppendETA()
64 AppendETA(-6)
6565 // create proxy reader
6666 reader := bar.ProxyReader(resp.Body)
6767 // and copy from reader
1919 // p := mpb.New().RefreshRate(80 * time.Millisecond).SetWidth(64)
2020
2121 name1 := "Bar#1: "
22 bar1 := p.AddBar(50).AppendPercentage().PrependName(name1, len(name1)).PrependETA(4)
22 bar1 := p.AddBar(50).
23 PrependName(name1, len(name1)).PrependETA(4).
24 AppendPercentage().TrimRightSpace()
25
2326 wg.Add(1)
2427 go func() {
2528 defer wg.Done()
3134 }
3235 }()
3336
34 bar2 := p.AddBar(100).AppendPercentage().PrependName("", 0-len(name1)).PrependETA(4)
37 bar2 := p.AddBar(100).
38 PrependName("", 0-len(name1)).PrependETA(4).
39 AppendPercentage().TrimRightSpace()
40
3541 wg.Add(1)
3642 go func() {
3743 defer wg.Done()
3945 for i := 0; i < 100; i++ {
4046 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
4147 bar2.Incr(1)
42 if bar2.Current() > 42 && p.RemoveBar(bar2) {
43 break
44 }
4548 blockSize = rand.Intn(maxBlockSize) + 1
4649 }
4750 }()
4851
49 bar3 := p.AddBar(80).AppendPercentage().PrependName("Bar#3: ", 0).PrependETA(4)
52 bar3 := p.AddBar(80).
53 PrependName("Bar#3: ", 0).PrependETA(4).
54 AppendPercentage().TrimRightSpace()
55
5056 wg.Add(1)
5157 go func() {
5258 defer wg.Done()