2021-11-09 18:44:17 +08:00
|
|
|
package utils
|
|
|
|
|
2023-01-31 12:48:28 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-01-31 12:48:28 +08:00
|
|
|
func NewBar(count int, MyStrStart, MyStrEnd string) *Bar {
|
2023-01-31 20:11:13 +08:00
|
|
|
tmpl := fmt.Sprintf(`{{counters . }} {{ bar . "[" "-" (cycle . "↖" "↗" "↘" "↙" ) "_" "]"}} %s {{string . "MyStr" | green}} %s `, MyStrStart, MyStrEnd)
|
2023-01-31 12:48:28 +08:00
|
|
|
bar := pb.ProgressBarTemplate(tmpl).Start(count)
|
|
|
|
return &Bar{pb: bar}
|
2021-11-09 23:39:42 +08:00
|
|
|
}
|
|
|
|
|
2023-01-31 12:48:28 +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()
|
2023-01-31 12:48:28 +08:00
|
|
|
}
|