| 45 | 45 |
var wg sync.WaitGroup
|
| 46 | 46 |
p := mpb.New(nil).SetWidth(60).BeforeRenderFunc(sortByProgressFunc())
|
| 47 | 47 |
|
| 48 | |
name1 := "Bar#1: "
|
|
48 |
name1 := "Bar#1:"
|
| 49 | 49 |
bar1 := p.AddBar(100).
|
| 50 | |
PrependName(name1, len(name1)).PrependFunc(getDecor()).
|
| 51 | |
AppendETA(-6)
|
|
50 |
PrependName(name1, 0, mpb.DwidthSync).
|
|
51 |
PrependCounters("%3s/%3s", 0, 10, mpb.DwidthSync|mpb.DextraSpace).
|
|
52 |
AppendETA(3, 0)
|
| 52 | 53 |
wg.Add(1)
|
| 53 | 54 |
go func() {
|
| 54 | 55 |
defer wg.Done()
|
|
| 61 | 62 |
}()
|
| 62 | 63 |
|
| 63 | 64 |
bar2 := p.AddBar(60).
|
| 64 | |
PrependName("", 0-len(name1)).PrependFunc(getDecor()).
|
| 65 | |
AppendETA(-6)
|
|
65 |
PrependName("", 0, mpb.DwidthSync).
|
|
66 |
PrependCounters("%3s/%3s", 0, 10, mpb.DwidthSync|mpb.DextraSpace).
|
|
67 |
AppendETA(3, 0)
|
| 66 | 68 |
wg.Add(1)
|
| 67 | 69 |
go func() {
|
| 68 | 70 |
defer wg.Done()
|
|
| 75 | 77 |
}()
|
| 76 | 78 |
|
| 77 | 79 |
bar3 := p.AddBar(80).
|
| 78 | |
PrependName("Bar#3: ", 0).PrependFunc(getDecor()).
|
| 79 | |
AppendETA(-6)
|
|
80 |
PrependName("Bar#3:", 0, mpb.DwidthSync).
|
|
81 |
PrependCounters("%3s/%3s", 0, 10, mpb.DwidthSync|mpb.DextraSpace).
|
|
82 |
AppendETA(3, 0)
|
| 80 | 83 |
wg.Add(1)
|
| 81 | 84 |
go func() {
|
| 82 | 85 |
defer wg.Done()
|
|
| 94 | 97 |
fmt.Println("stop")
|
| 95 | 98 |
}
|
| 96 | 99 |
|
| 97 | |
func getDecor() mpb.DecoratorFunc {
|
| 98 | |
return func(s *mpb.Statistics, myWidth chan<- int, maxWidth <-chan int) string {
|
| 99 | |
str := fmt.Sprintf("%d/%d", s.Current, s.Total)
|
| 100 | |
return fmt.Sprintf("%-7s", str)
|
| 101 | |
}
|
| 102 | |
}
|
| 103 | |
|
| 104 | 100 |
func sleep(blockSize int) {
|
| 105 | 101 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
| 106 | 102 |
}
|