@@ -186,6 +186,7 @@ type Spinner struct {
186
186
color func (a ... interface {}) string // default color is white
187
187
Writer io.Writer // to make testing better, exported so users have access. Use `WithWriter` to update after initialization.
188
188
active bool // active holds the state of the spinner
189
+ enabled bool // indicates whether the spinner is enabled or not
189
190
stopChan chan struct {} // stopChan is a channel used to stop the indicator
190
191
HideCursor bool // hideCursor determines if the cursor is visible
191
192
PreUpdate func (s * Spinner ) // will be triggered before every spinner update
@@ -202,6 +203,7 @@ func New(cs []string, d time.Duration, options ...Option) *Spinner {
202
203
Writer : color .Output ,
203
204
stopChan : make (chan struct {}, 1 ),
204
205
active : false ,
206
+ enabled : true ,
205
207
HideCursor : true ,
206
208
}
207
209
@@ -271,10 +273,27 @@ func (s *Spinner) Active() bool {
271
273
return s .active
272
274
}
273
275
276
+ // Enabled returns whether or not the spinner is enabled.
277
+ func (s * Spinner ) Enabled () bool {
278
+ return s .enabled
279
+ }
280
+
281
+ // Enable enables and restarts the spinner
282
+ func (s * Spinner ) Enable () {
283
+ s .enabled = true
284
+ s .Restart ()
285
+ }
286
+
287
+ // Disable stops and disables the spinner
288
+ func (s * Spinner ) Disable () {
289
+ s .enabled = false
290
+ s .Stop ()
291
+ }
292
+
274
293
// Start will start the indicator.
275
294
func (s * Spinner ) Start () {
276
295
s .mu .Lock ()
277
- if s .active || ! isRunningInTerminal () {
296
+ if s .active || ! s . enabled || ! isRunningInTerminal () {
278
297
s .mu .Unlock ()
279
298
return
280
299
}
0 commit comments