-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress_bar.go
49 lines (43 loc) · 1.12 KB
/
progress_bar.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
package acp
import (
"fmt"
"os"
"time"
"github.com/schollz/progressbar/v3"
)
func NewProgressBar() EventHandler {
// progressBar := progressbar.DefaultBytes(1, "[0/0] indexing...")
bar := progressbar.NewOptions64(
1,
progressbar.OptionSetDescription("[0/0] indexing..."),
progressbar.OptionSetWriter(os.Stderr),
progressbar.OptionShowBytes(true),
progressbar.OptionSetWidth(10),
progressbar.OptionThrottle(65*time.Millisecond),
progressbar.OptionShowCount(),
progressbar.OptionOnCompletion(func() {}),
progressbar.OptionSpinnerType(14),
progressbar.OptionFullWidth(),
progressbar.OptionSetRenderBlankState(true),
)
var totalFiles int64
return func(ev Event) {
switch e := ev.(type) {
case *EventUpdateCount:
totalFiles = e.Files
bar.Describe(fmt.Sprintf("[0/%d] indexing...", totalFiles))
bar.ChangeMax64(e.Bytes)
return
case *EventUpdateProgress:
bar.Set64(e.Bytes)
if !e.Finished {
bar.Describe(fmt.Sprintf("[%d/%d] copying...", e.Files, totalFiles))
return
}
bar.Describe(fmt.Sprintf("[%d/%d] finishing...", e.Files, totalFiles))
return
default:
return
}
}
}