CloudflareSpeedTest/utils/progress.go

26 lines
527 B
Go
Raw Normal View History

2021-11-09 18:44:17 +08:00
package utils
import (
"fmt"
"github.com/cheggaaa/pb/v3"
)
2021-11-09 23:39:42 +08:00
type Bar struct {
2021-11-10 12:25:10 +08:00
pb *pb.ProgressBar
2021-11-09 23:39:42 +08:00
}
func NewBar(count int, MyStrStart, MyStrEnd string) *Bar {
tmpl := fmt.Sprintf(`{{counters . }} {{ bar . "[" "-" (cycle . "↖" "↗" "↘" "↙" ) "_" "]"}} %s {{string . "MyStr" | green}} %s `, MyStrStart, MyStrEnd)
bar := pb.ProgressBarTemplate(tmpl).Start(count)
return &Bar{pb: bar}
2021-11-09 23:39:42 +08:00
}
func (b *Bar) Grow(num int, MyStrVal string) {
b.pb.Set("MyStr", MyStrVal).Add(num)
2021-11-10 12:25:10 +08:00
}
func (b *Bar) Done() {
b.pb.Finish()
}