-
Notifications
You must be signed in to change notification settings - Fork 7
/
progress.go
39 lines (36 loc) · 1.16 KB
/
progress.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
package main
import (
"fmt"
"github.com/k0kubun/go-ansi"
"github.com/schollz/progressbar/v3"
"os"
"time"
)
// bytesBar 自定义的progress风格,用以展示文件的读写进度
func bytesBar(size int64, name string) *progressbar.ProgressBar {
if len(name) > 50 {
name = fmt.Sprintf("%s...", name[0:51])
}
return progressbar.NewOptions(int(size),
progressbar.OptionSetWriter(ansi.NewAnsiStderr()), // 使用ansi防止奇怪的换行等显示错误
progressbar.OptionUseANSICodes(true), // avoid progressbar downsize error
progressbar.OptionEnableColorCodes(true),
progressbar.OptionShowBytes(true),
progressbar.OptionSetDescription(name),
progressbar.OptionFullWidth(),
progressbar.OptionThrottle(65*time.Millisecond),
progressbar.OptionSetRenderBlankState(true),
progressbar.OptionSpinnerType(14),
progressbar.OptionShowCount(),
progressbar.OptionOnCompletion(func() {
fmt.Fprint(os.Stderr, "\n")
}),
progressbar.OptionSetWidth(10),
progressbar.OptionSetTheme(progressbar.Theme{
Saucer: "[green]=[reset]",
SaucerHead: "[green]>[reset]",
SaucerPadding: " ",
BarStart: "[",
BarEnd: "]",
}))
}