Skip to content

Commit 4f72a65

Browse files
authored
Merge pull request #227 from polymorcodeus/main
Added OptionSetSpinnerColorCode to support color codes for spinners.
2 parents 56ad4a7 + bbedc95 commit 4f72a65

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

progressbar.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ type config struct {
8181
colorCodes bool
8282
// custom colors to use for colorCodes
8383
customColors map[string]string
84+
// color to apply to spinner
85+
spinnerColorCode string
8486

8587
// show rate of change in kB/sec or MB/sec
8688
showBytes bool
@@ -290,6 +292,13 @@ func OptionSetCustomColorCodes(customColors map[string]string) Option {
290292
}
291293
}
292294

295+
// OptionSetSpinnerColorCode sets color code for spinner
296+
func OptionSetSpinnerColorCode(colorCode string) Option {
297+
return func(p *ProgressBar) {
298+
p.config.spinnerColorCode = colorCode
299+
}
300+
}
301+
293302
// OptionSetElapsedTime will enable elapsed time. Always enabled if OptionSetPredictTime is true.
294303
func OptionSetElapsedTime(elapsedTime bool) Option {
295304
return func(p *ProgressBar) {
@@ -1294,6 +1303,10 @@ func renderProgressBar(c config, s *state) (int, error) {
12941303
spinner = selectedSpinner[s.spinnerIdx]
12951304
s.spinnerIdx = (s.spinnerIdx + 1) % len(selectedSpinner)
12961305
}
1306+
// if set add spinner color code
1307+
if c.spinnerColorCode != "" && c.colorCodes {
1308+
spinner = "[" + c.spinnerColorCode + "]" + spinner + "[reset]"
1309+
}
12971310
if c.elapsedTime {
12981311
if c.showDescriptionAtLineEnd {
12991312
str = fmt.Sprintf("\r%s %s [%s] %s ",

0 commit comments

Comments
 (0)