examples update
Vladimir Bauer
9 years ago
| 40 | 40 |
}
|
| 41 | 41 |
|
| 42 | 42 |
func (b *Bar) PrependETA(padding int) *Bar {
|
| 43 | |
layout := "ETA%" + strconv.Itoa(padding) + "s"
|
|
43 |
layout := "ETA% " + strconv.Itoa(padding) + "s"
|
| 44 | 44 |
b.PrependFunc(func(s *Statistics) string {
|
| 45 | 45 |
return fmt.Sprintf(layout, time.Duration(s.Eta().Seconds())*time.Second)
|
| 46 | 46 |
})
|
| 47 | 47 |
return b
|
| 48 | 48 |
}
|
| 49 | 49 |
|
| 50 | |
func (b *Bar) AppendETA() *Bar {
|
|
50 |
func (b *Bar) AppendETA(padding int) *Bar {
|
|
51 |
layout := "ETA% " + strconv.Itoa(padding) + "s"
|
| 51 | 52 |
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)
|
| 53 | 54 |
})
|
| 54 | 55 |
return b
|
| 55 | 56 |
}
|
| 59 | 59 |
|
| 60 | 60 |
// create bar with appropriate decorators
|
| 61 | 61 |
bar := p.AddBar(int(size)).
|
|
62 |
PrependName(name, len(name)).
|
| 62 | 63 |
PrependCounters(mpb.UnitBytes, 20).
|
| 63 | |
PrependName(name, len(name)).
|
| 64 | |
AppendETA()
|
|
64 |
AppendETA(-6)
|
| 65 | 65 |
// create proxy reader
|
| 66 | 66 |
reader := bar.ProxyReader(resp.Body)
|
| 67 | 67 |
// and copy from reader
|
| 19 | 19 |
// p := mpb.New().RefreshRate(80 * time.Millisecond).SetWidth(64)
|
| 20 | 20 |
|
| 21 | 21 |
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 |
|
| 23 | 26 |
wg.Add(1)
|
| 24 | 27 |
go func() {
|
| 25 | 28 |
defer wg.Done()
|
|
| 31 | 34 |
}
|
| 32 | 35 |
}()
|
| 33 | 36 |
|
| 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 |
|
| 35 | 41 |
wg.Add(1)
|
| 36 | 42 |
go func() {
|
| 37 | 43 |
defer wg.Done()
|
|
| 39 | 45 |
for i := 0; i < 100; i++ {
|
| 40 | 46 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
| 41 | 47 |
bar2.Incr(1)
|
| 42 | |
if bar2.Current() > 42 && p.RemoveBar(bar2) {
|
| 43 | |
break
|
| 44 | |
}
|
| 45 | 48 |
blockSize = rand.Intn(maxBlockSize) + 1
|
| 46 | 49 |
}
|
| 47 | 50 |
}()
|
| 48 | 51 |
|
| 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 |
|
| 50 | 56 |
wg.Add(1)
|
| 51 | 57 |
go func() {
|
| 52 | 58 |
defer wg.Done()
|