-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress.go
43 lines (33 loc) · 914 Bytes
/
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
40
41
42
43
package veracity
import (
"github.com/gosuri/uiprogress"
)
type noopStagedProgressor struct{}
func (p *noopStagedProgressor) Completed() {}
func (p *noopStagedProgressor) Current() int { return 0 }
type Progresser interface {
Completed()
}
func NewNoopProgress() Progresser {
return &noopStagedProgressor{}
}
type progress struct {
// bar represents progress towards completion of massifs for a single tenant
bar *uiprogress.Bar
}
func NewStagedProgress(prefix string, count int) Progresser {
if count == 0 {
return NewNoopProgress()
}
return &progress{
bar: uiprogress.AddBar(count).PrependElapsed().PrependFunc(func(b *uiprogress.Bar) string {
return prefix + ":"
}),
}
}
// Current returns the index of the current step.
func (p *progress) Current() int { return p.bar.Current() }
// Completed advances the progress bar one increment
func (p *progress) Completed() {
p.bar.Incr()
}