forked from schollz/progressbar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
multi.go
62 lines (58 loc) · 1.16 KB
/
multi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"github.com/HarryWang29/progressbar/v4"
"os"
"sync"
"time"
)
func main() {
waitTime := time.Millisecond * 100
pb := progressbar.NewMultiProgress()
pb.Start()
var wg sync.WaitGroup
//bar1, _ := pb.Add64Bar("1", 20)
_, _ = pb.Add64Bar("1", 80)
wg.Add(1)
go func() {
defer wg.Done()
for i := 1; i <= 80; i++ {
//bar1.Add64(1)
pb.BarAdd("1", 1)
time.Sleep(waitTime)
}
}()
//bar2, _ := pb.AddDefaultBar("2", 40)
_, _ = pb.AddDefaultBar("2", 40)
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 40; i++ {
//bar2.Add64(1)
pb.BarAdd("2", 1)
time.Sleep(waitTime)
}
}()
time.Sleep(time.Second)
bar3 := progressbar.NewOptions(100,
progressbar.OptionSetWriter(os.Stdout),
progressbar.OptionSetWidth(15),
progressbar.OptionSetDescription(fmt.Sprintf("downloading %s ...", "test")),
progressbar.OptionSetTheme(progressbar.Theme{
Saucer: "=",
SaucerHead: ">",
SaucerPadding: " ",
BarStart: "[",
BarEnd: "]",
}))
pb.AddBar("3", bar3)
wg.Add(1)
go func() {
defer wg.Done()
for i := 1; i <= 100; i++ {
bar3.Add64(1)
time.Sleep(waitTime)
}
}()
wg.Wait()
}