-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
171 lines (141 loc) · 4.88 KB
/
option.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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package progressbar
import (
"io"
"time"
"github.com/schollz/progressbar/v3"
)
type Options struct {
options []progressbar.Option
}
func ProgressOptions() *Options {
return &Options{
options: make([]progressbar.Option, 0),
}
}
func DefaultOptions() *Options {
return &Options{
options: make([]progressbar.Option, 0),
}
}
func (p *Options) Writer(w io.Writer) *Options {
p.options = append(p.options, progressbar.OptionSetWriter(w))
return p
}
// Width sets the width of the bar
func (p *Options) Width(width int) *Options {
p.options = append(p.options, progressbar.OptionSetWidth(width))
return p
}
// FullWidth sets the bar to be full width
func (p *Options) FullWidth() *Options {
p.options = append(p.options, progressbar.OptionFullWidth())
return p
}
func (p *Options) DisShowTotalBytes(val bool) *Options {
p.options = append(p.options, progressbar.OptionShowTotalBytes(val))
return p
}
func (p *Options) SpinnerChangeInterval(interval time.Duration) *Options {
p.options = append(p.options, progressbar.OptionSetSpinnerChangeInterval(interval))
return p
}
// SpinnerType sets the type of spinner used for indeterminate bars
func (p *Options) SpinnerType(spinnerType int) *Options {
p.options = append(p.options, progressbar.OptionSpinnerType(spinnerType))
return p
}
// SpinnerCustom sets the spinner used for indeterminate bars to the passed
// slice of string
func (p *Options) SpinnerCustom(spinner ...string) *Options {
p.options = append(p.options, progressbar.OptionSpinnerCustom(spinner))
return p
}
// Theme sets the elements the bar is constructed with.
// There are two pre-defined themes you can use: ThemeASCII and ThemeUnicode.
func (p *Options) Theme(t progressbar.Theme) *Options {
p.options = append(p.options, progressbar.OptionSetTheme(t))
return p
}
// DisEnableVisibility enable the visibility
func (p *Options) DisEnableVisibility() *Options {
p.options = append(p.options, progressbar.OptionSetVisibility(false))
return p
}
func (p *Options) RenderBlankState(r bool) *Options {
p.options = append(p.options, progressbar.OptionSetRenderBlankState(r))
return p
}
func (p *Options) Throttle(duration time.Duration) *Options {
p.options = append(p.options, progressbar.OptionThrottle(duration))
return p
}
// EnableShowCount will also print current count out of total
func (p *Options) EnableShowCount() *Options {
p.options = append(p.options, progressbar.OptionShowCount())
return p
}
// EnableShowIts will also print the iterations/second
func (p *Options) EnableShowIts() *Options {
p.options = append(p.options, progressbar.OptionShowIts())
return p
}
func (p *Options) Completion(cmpl func()) *Options {
p.options = append(p.options, progressbar.OptionOnCompletion(cmpl))
return p
}
// EnableColorCodes enables support for color codes ,you need there is a color code library
// using mitchellh/colorstring
func (p *Options) EnableColorCodes() *Options {
p.options = append(p.options, progressbar.OptionEnableColorCodes(true))
return p
}
func (p *Options) ElapsedTime(elapsedTime bool) *Options {
p.options = append(p.options, progressbar.OptionSetElapsedTime(elapsedTime))
return p
}
// DisEnablePredictTime will also attempt to predict the time remaining.
func (p *Options) DisEnablePredictTime() *Options {
p.options = append(p.options, progressbar.OptionSetPredictTime(false))
return p
}
// EnableElapsedTimeOnFinish will keep the display of elapsed time on finish.
func (p *Options) EnableElapsedTimeOnFinish() *Options {
p.options = append(p.options, progressbar.OptionShowElapsedTimeOnFinish())
return p
}
func (p *Options) SetItsString(iterationString string) *Options {
p.options = append(p.options, progressbar.OptionSetItsString(iterationString))
return p
}
func (p *Options) ClearOnFinish() *Options {
p.options = append(p.options, progressbar.OptionClearOnFinish())
return p
}
// EnableShowBytes will update the progress bar
// configuration settings to display/hide kBytes/Sec
func (p *Options) EnableShowBytes() *Options {
p.options = append(p.options, progressbar.OptionShowBytes(true))
return p
}
// EnableANSICodes will use more optimized terminal i/o.
//
// Only useful in environments with support for ANSI escape sequences.
func (p *Options) EnableANSICodes() *Options {
p.options = append(p.options, progressbar.OptionUseANSICodes(true))
return p
}
// EnableIECUnits will enable IEC units (e.g. MiB) instead of the default
// SI units (e.g. MB).
func (p *Options) EnableIECUnits() *Options {
p.options = append(p.options, progressbar.OptionUseIECUnits(true))
return p
}
// EnableDescriptionAtLineEnd defines whether description should be written at line end instead of line start
func (p *Options) EnableDescriptionAtLineEnd() *Options {
p.options = append(p.options, progressbar.OptionShowDescriptionAtLineEnd())
return p
}
func (p *Options) MaxDetailRow(row int) *Options {
p.options = append(p.options, progressbar.OptionSetMaxDetailRow(row))
return p
}