-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethods.go
More file actions
80 lines (68 loc) · 2.1 KB
/
Copy pathmethods.go
File metadata and controls
80 lines (68 loc) · 2.1 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package progressbar
import "fmt"
// Update updates the percentage and returns the string for display
func (p *progressBar) Update(percent int) (string, error) {
if percent < 0 || percent > 100 {
return "", fmt.Errorf("the percent parameter must be no less than 0 and no more than 100, percent = %d", percent)
}
p.percent = percent
if p.config.withSpinner {
if percent == 0 {
p.spinnerState = 0
} else {
p.spinnerState = (p.spinnerState + 1) % p.spinnerLen
}
}
return p.render(), nil
}
// SetColors sets colors for frames, informers and fill
func (p *progressBar) SetColors(newColors [2]string) {
p.config.colors = newColors
}
// SetPercent sets the fill percentage
func (p *progressBar) SetPercent(newPercent int) error {
if newPercent > 100 {
return fmt.Errorf("the percent variable must not be greater than 100, newPercent = %d", newPercent)
}
p.percent = newPercent
return nil
}
// SetBarLen sets the length of the progress bar
func (p *progressBar) SetBarLen(newBarLen int) error {
if newBarLen < 0 {
return fmt.Errorf("newBarLen value must not be less than 0, newBarLen = %d", newBarLen)
}
p.barLen = newBarLen
return nil
}
// SetEdges sets edge symbols
func (p *progressBar) SetEdges(newEdges [2]string) {
p.config.edges = newEdges
}
// SetFillers sets the fill and void characters
func (p *progressBar) SetFillers(newFillers [2]string) {
p.config.fillers = newFillers
}
// SetSpinner sets new spinner in progress bar
func (p *progressBar) SetSpinner(newSpinner []string) error {
newSpinnerLen := len(newSpinner)
if newSpinnerLen < 1 {
return fmt.Errorf("spinner cut length cannot be less than 1, current length: %d", newSpinnerLen)
}
p.config.spinner = newSpinner
p.spinnerLen = newSpinnerLen
p.spinnerState = 0
return nil
}
// WithPercent turns on/off the display of percentages
func (p *progressBar) WithPercent(show bool) {
p.config.withPercent = show
}
// WithSpinner turns the spinner on/off
func (p *progressBar) WithSpinner(show bool) {
p.config.withSpinner = show
}
// GetCurrentPercent get a set percentage
func (p *progressBar) GetCurrentPercent() int {
return p.percent
}