-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogressBar.go
48 lines (40 loc) · 1.6 KB
/
progressBar.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
package utils
import (
"fmt"
"github.com/cheggaaa/pb/v3"
)
func ProgressBar(FuncName string, Count int64, Func func()) {
count := Count
// create and start new bar
//bar := pb.StartNew(count)
// start bar from 'default' template
// bar := pb.Default.Start(count)
// start bar from 'simple' template
// bar := pb.Simple.Start(count)
// start bar from 'full' template
// bar := pb.Full.Start(count)
tmpl := fmt.Sprintf("{{ red \"%s:\" }} {{ bar . \"[-\" \"-\" (cycle . \"—>\" \"↖\" \"↗\" \"↘\" \"↙\") \".\" \">]\"}} {{speed . | rndcolor }} {{percent .}} {{string . \"my_green_string\" | green}} {{string . \"my_blue_string\" | blue}}", FuncName)
// start bar based on our template
bar := pb.ProgressBarTemplate(tmpl).Start64(count)
// set values for string elements
//bar.Set("my_green_string", "描述1").Set("my_blue_string", "描述2")
for i := 0; i < int(count); i++ {
bar.Increment()
Func()
}
bar.Finish()
}
//func ProgressBarTask() {
// time.Sleep(1 * time.Second)
// // 尽量不要有输出,否则会换行
// // Try not to have output, otherwise I will wrap.
// // Try not to have output, otherwise I will wrap.
// fmt.Println("ProgressBar test ..")
//}
//需要指定进度条前缀、处理的次数,比如处理多少个文件,发出多少个请求之类的
//You need to specify the progress bar prefix, the number of times processed, such as how many files are processed, how many requests are made, and so on.
//总等待时间 = 次数 * 你程序消耗时间
//Total waiting time = times * your program consumes time
//func main() {
// ProgressBar("test", 10,ProgressBarTask)
//}