-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathprogress.go
More file actions
46 lines (37 loc) · 986 Bytes
/
progress.go
File metadata and controls
46 lines (37 loc) · 986 Bytes
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
package main
import (
"fmt"
"github.com/schollz/progressbar/v3"
)
// ProgressUpdater is a common interface for progress tracking.
type ProgressUpdater interface {
Increment()
Finish()
}
// realProgressBar wraps schollz/progressbar.
type realProgressBar struct {
bar *progressbar.ProgressBar
}
func newProgressBar(total int, description string) ProgressUpdater {
if silent {
return &noopProgressBar{}
}
bar := progressbar.NewOptions(total,
progressbar.OptionSetDescription(fmt.Sprintf(" %s", description)),
progressbar.OptionSetWidth(30),
progressbar.OptionShowCount(),
progressbar.OptionClearOnFinish(),
progressbar.OptionSetPredictTime(false),
)
return &realProgressBar{bar: bar}
}
func (p *realProgressBar) Increment() {
p.bar.Add(1)
}
func (p *realProgressBar) Finish() {
p.bar.Finish()
}
// noopProgressBar is used in silent/JSON mode.
type noopProgressBar struct{}
func (n *noopProgressBar) Increment() {}
func (n *noopProgressBar) Finish() {}