@@ -13,6 +13,7 @@ import (
13
13
14
14
var (
15
15
flagAutoStop = flag .Bool ("auto-stop" , false , "Auto-stop rendering?" )
16
+ flagCustomRenderer = flag .Bool ("custom-renderer" , false , "Use custom render functions with rainbow colors" )
16
17
flagHideETA = flag .Bool ("hide-eta" , false , "Hide the ETA?" )
17
18
flagHideETAOverall = flag .Bool ("hide-eta-overall" , false , "Hide the ETA in the overall tracker?" )
18
19
flagHideOverallTracker = flag .Bool ("hide-overall" , false , "Hide the Overall Tracker?" )
27
28
flagRandomDefer = flag .Bool ("rnd-defer" , false , "Introduce random deferred starts" )
28
29
flagRandomRemove = flag .Bool ("rnd-remove" , false , "Introduce random remove of trackers on completion" )
29
30
flagRandomLogs = flag .Bool ("rnd-logs" , false , "Output random logs in the middle of tracking" )
30
- flagCustomRender = flag .Bool ("custom-render" , false , "Use custom render functions with rainbow colors" )
31
31
32
32
messageColors = []text.Color {
33
33
text .FgRed ,
42
42
timeStart = time .Now ()
43
43
)
44
44
45
+ // customTrackerDeterminateRenderer creates a progress bar using rainbow colors for determinate progress
46
+ func customTrackerDeterminateRenderer (value int64 , total int64 , maxLen int ) string {
47
+ progress := float64 (value ) / float64 (total )
48
+ completed := int (progress * float64 (maxLen ))
49
+
50
+ var result strings.Builder
51
+ for i := 0 ; i < maxLen ; i ++ {
52
+ if i < completed {
53
+ // Use rainbow colors based on position in the progress bar
54
+ colorIdx := (i * 6 ) / maxLen // Map position to 6 rainbow colors
55
+ colors := []text.Color {
56
+ text .FgRed ,
57
+ text .FgYellow ,
58
+ text .FgGreen ,
59
+ text .FgCyan ,
60
+ text .FgBlue ,
61
+ text .FgMagenta ,
62
+ }
63
+ if colorIdx >= len (colors ) {
64
+ colorIdx = len (colors ) - 1
65
+ }
66
+ result .WriteString (colors [colorIdx ].Sprint ("█" ))
67
+ } else {
68
+ result .WriteString (text .FgHiBlack .Sprint ("░" ))
69
+ }
70
+ }
71
+
72
+ return result .String ()
73
+ }
74
+
75
+ // customTrackerIndeterminateRenderer creates a progress bar using rotating rainbow colors for indeterminate progress
76
+ func customTrackerIndeterminateRenderer (maxLen int ) string {
77
+ // For indeterminate progress, use rotating rainbow colors
78
+ colors := []text.Color {
79
+ text .FgRed ,
80
+ text .FgYellow ,
81
+ text .FgGreen ,
82
+ text .FgCyan ,
83
+ text .FgBlue ,
84
+ text .FgMagenta ,
85
+ }
86
+ idx := int (time .Now ().UnixNano ()/ 100000000 ) % len (colors )
87
+ return colors [idx ].Sprint (strings .Repeat ("█" , maxLen ))
88
+ }
89
+
45
90
func getMessage (idx int64 , units * progress.Units ) string {
46
91
var message string
47
92
switch units {
@@ -121,51 +166,6 @@ func trackSomething(pw progress.Writer, idx int64, updateMessage bool) {
121
166
}
122
167
}
123
168
124
- // customTrackerRender creates a progress bar using rainbow colors for determinate progress
125
- func customTrackerRender (value int64 , total int64 , maxLen int ) string {
126
- progress := float64 (value ) / float64 (total )
127
- completed := int (progress * float64 (maxLen ))
128
-
129
- var result strings.Builder
130
- for i := 0 ; i < maxLen ; i ++ {
131
- if i < completed {
132
- // Use rainbow colors based on position in the progress bar
133
- colorIdx := (i * 6 ) / maxLen // Map position to 6 rainbow colors
134
- colors := []text.Color {
135
- text .FgRed ,
136
- text .FgYellow ,
137
- text .FgGreen ,
138
- text .FgCyan ,
139
- text .FgBlue ,
140
- text .FgMagenta ,
141
- }
142
- if colorIdx >= len (colors ) {
143
- colorIdx = len (colors ) - 1
144
- }
145
- result .WriteString (colors [colorIdx ].Sprint ("█" ))
146
- } else {
147
- result .WriteString (text .FgHiBlack .Sprint ("░" ))
148
- }
149
- }
150
-
151
- return result .String ()
152
- }
153
-
154
- // customTrackerIndeterminateRender creates a progress bar using rotating rainbow colors for indeterminate progress
155
- func customTrackerIndeterminateRender (maxLen int ) string {
156
- // For indeterminate progress, use rotating rainbow colors
157
- colors := []text.Color {
158
- text .FgRed ,
159
- text .FgYellow ,
160
- text .FgGreen ,
161
- text .FgCyan ,
162
- text .FgBlue ,
163
- text .FgMagenta ,
164
- }
165
- idx := int (time .Now ().UnixNano ()/ 100000000 ) % len (colors )
166
- return colors [idx ].Sprint (strings .Repeat ("█" , maxLen ))
167
- }
168
-
169
169
func main () {
170
170
flag .Parse ()
171
171
fmt .Printf ("Tracking Progress of %d trackers ...\n \n " , * flagNumTrackers )
@@ -193,10 +193,9 @@ func main() {
193
193
pw .Style ().Visibility .Pinned = * flagShowPinned
194
194
195
195
// set up custom render functions if flag is enabled
196
- if * flagCustomRender {
197
- pw .Style ().Renderer .TrackerDeterminate = customTrackerRender
198
- pw .Style ().Renderer .TrackerIndeterminate = customTrackerIndeterminateRender
199
- fmt .Println ("Using custom render functions with rainbow colors!" )
196
+ if * flagCustomRenderer {
197
+ pw .Style ().Renderer .TrackerDeterminate = customTrackerDeterminateRenderer
198
+ pw .Style ().Renderer .TrackerIndeterminate = customTrackerIndeterminateRenderer
200
199
}
201
200
202
201
// call Render() in async mode; yes we don't have any trackers at the moment
0 commit comments