-
Notifications
You must be signed in to change notification settings - Fork 122
/
style.go
217 lines (198 loc) · 7.24 KB
/
style.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package progress
import (
"time"
"github.com/jedib0t/go-pretty/v6/text"
)
// Style declares how to render the Progress/Trackers.
type Style struct {
Name string // name of the Style
Chars StyleChars // characters to use on the progress bar
Colors StyleColors // colors to use on the progress bar
Options StyleOptions // misc. options for the progress bar
Visibility StyleVisibility // show/hide components of the progress bar(s)
}
var (
// StyleDefault uses ASCII text to render the Trackers.
StyleDefault = Style{
Name: "StyleDefault",
Chars: StyleCharsDefault,
Colors: StyleColorsDefault,
Options: StyleOptionsDefault,
Visibility: StyleVisibilityDefault,
}
// StyleBlocks uses UNICODE Block Drawing characters to render the Trackers.
StyleBlocks = Style{
Name: "StyleBlocks",
Chars: StyleCharsBlocks,
Colors: StyleColorsDefault,
Options: StyleOptionsDefault,
Visibility: StyleVisibilityDefault,
}
// StyleCircle uses UNICODE Circle runes to render the Trackers.
StyleCircle = Style{
Name: "StyleCircle",
Chars: StyleCharsCircle,
Colors: StyleColorsDefault,
Options: StyleOptionsDefault,
Visibility: StyleVisibilityDefault,
}
// StyleRhombus uses UNICODE Rhombus runes to render the Trackers.
StyleRhombus = Style{
Name: "StyleRhombus",
Chars: StyleCharsRhombus,
Colors: StyleColorsDefault,
Options: StyleOptionsDefault,
Visibility: StyleVisibilityDefault,
}
)
// StyleChars defines the characters/strings to use for rendering the Tracker.
type StyleChars struct {
BoxLeft string // left-border
BoxRight string // right-border
Finished string // finished block
Finished25 string // 25% finished block
Finished50 string // 50% finished block
Finished75 string // 75% finished block
Indeterminate IndeterminateIndicatorGenerator
Unfinished string // 0% finished block
}
var (
// StyleCharsDefault uses simple ASCII characters.
StyleCharsDefault = StyleChars{
BoxLeft: "[",
BoxRight: "]",
Finished: "#",
Finished25: ".",
Finished50: ".",
Finished75: ".",
Indeterminate: IndeterminateIndicatorMovingBackAndForth("<#>", DefaultUpdateFrequency/2),
Unfinished: ".",
}
// StyleCharsBlocks uses UNICODE Block Drawing characters.
StyleCharsBlocks = StyleChars{
BoxLeft: "║",
BoxRight: "║",
Finished: "█",
Finished25: "░",
Finished50: "▒",
Finished75: "▓",
Indeterminate: IndeterminateIndicatorMovingBackAndForth("▒█▒", DefaultUpdateFrequency/2),
Unfinished: "░",
}
// StyleCharsCircle uses UNICODE Circle characters.
StyleCharsCircle = StyleChars{
BoxLeft: "(",
BoxRight: ")",
Finished: "●",
Finished25: "○",
Finished50: "○",
Finished75: "○",
Indeterminate: IndeterminateIndicatorMovingBackAndForth("○●○", DefaultUpdateFrequency/2),
Unfinished: "◌",
}
// StyleCharsRhombus uses UNICODE Rhombus characters.
StyleCharsRhombus = StyleChars{
BoxLeft: "<",
BoxRight: ">",
Finished: "◆",
Finished25: "◈",
Finished50: "◈",
Finished75: "◈",
Indeterminate: IndeterminateIndicatorMovingBackAndForth("◈◆◈", DefaultUpdateFrequency/2),
Unfinished: "◇",
}
)
// StyleColors defines what colors to use for various parts of the Progress and
// Tracker texts.
type StyleColors struct {
Message text.Colors // message text colors
Error text.Colors // error text colors
Percent text.Colors // percentage text colors
Pinned text.Colors // color of the pin message
Stats text.Colors // stats text (time, value) colors
Time text.Colors // time text colors (overrides Stats)
Tracker text.Colors // tracker text colors
Value text.Colors // value text colors (overrides Stats)
Speed text.Colors // speed text colors
}
var (
// StyleColorsDefault defines sane color choices - None.
StyleColorsDefault = StyleColors{}
// StyleColorsExample defines a few choice color options. Use this is just
// as an example to customize the Tracker/text colors.
StyleColorsExample = StyleColors{
Message: text.Colors{text.FgWhite},
Error: text.Colors{text.FgRed},
Percent: text.Colors{text.FgHiRed},
Pinned: text.Colors{text.BgHiBlack, text.FgWhite, text.Bold},
Stats: text.Colors{text.FgHiBlack},
Time: text.Colors{text.FgGreen},
Tracker: text.Colors{text.FgYellow},
Value: text.Colors{text.FgCyan},
Speed: text.Colors{text.FgMagenta},
}
)
// StyleOptions defines misc. options to control how the Tracker or its parts
// gets rendered.
type StyleOptions struct {
DoneString string // "done!" string
ErrorString string // "error!" string
ETAPrecision time.Duration // precision for ETA
ETAString string // string for ETA
Separator string // text between message and tracker
SnipIndicator string // text denoting message snipping
PercentFormat string // formatting to use for percentage
PercentIndeterminate string // when percentage cannot be computed
SpeedPosition Position // where speed is displayed in stats
SpeedPrecision time.Duration // precision for speed
SpeedOverallFormatter UnitsFormatter // formatter for the overall tracker speed
SpeedSuffix string // suffix (/s)
TimeDonePrecision time.Duration // precision for time when done
TimeInProgressPrecision time.Duration // precision for time when in progress
TimeOverallPrecision time.Duration // precision for overall time
}
// StyleOptionsDefault defines sane defaults for the Options. Use this as an
// example to customize the Tracker rendering.
var StyleOptionsDefault = StyleOptions{
DoneString: "done!",
ErrorString: "fail!",
ETAPrecision: time.Second,
ETAString: "~ETA",
PercentFormat: "%5.2f%%",
PercentIndeterminate: " ??? ",
Separator: " ... ",
SnipIndicator: "~",
SpeedPosition: PositionRight,
SpeedPrecision: time.Microsecond,
SpeedOverallFormatter: FormatNumber,
SpeedSuffix: "/s",
TimeDonePrecision: time.Millisecond,
TimeInProgressPrecision: time.Microsecond,
TimeOverallPrecision: time.Second,
}
// StyleVisibility controls what gets shown and what gets hidden.
type StyleVisibility struct {
ETA bool // ETA for each tracker
ETAOverall bool // ETA for the overall tracker
Percentage bool // tracker progress percentage value
Pinned bool // pin message
Speed bool // tracker speed
SpeedOverall bool // overall tracker speed
Time bool // tracker time taken
Tracker bool // tracker ([===========-----------])
TrackerOverall bool // overall tracker
Value bool // tracker value
}
// StyleVisibilityDefault defines sane defaults for the Visibility.
var StyleVisibilityDefault = StyleVisibility{
ETA: false,
ETAOverall: true,
Percentage: true,
Pinned: true,
Speed: false,
SpeedOverall: false,
Time: true,
Tracker: true,
TrackerOverall: false,
Value: true,
}