@@ -46,21 +46,22 @@ func getStatusSymbols() (successSymbol, errorSymbol string) {
46
46
47
47
// Spinner defines our spinner data.
48
48
type Spinner struct {
49
- message * synx.String // message to display
50
- stopChan chan struct {} // exit channel
51
- speedUpdated * synx.Bool // Indicates speed has been updated
52
- exitStatus status // Status of exit
53
- successSymbol * synx.String // Symbol printed when Success() called
54
- errorSymbol * synx.String // Symbol printed when Error() called
55
- spinFrames * synx.StringSlice // Spinset frames
56
- frameNumber int // Current frame [default 0]
57
- termWidth * synx.Int // Terminal width
58
- termHeight * synx.Int // Terminal Height
59
- spinSpeed * synx.Int // Delay between spinner updates in milliseconds [default 100ms]
60
- currentLine * synx.String // The current line being displayed
61
- running * synx.Bool // Indicates if the spinner is running
62
- abortMessage * synx.String // Printed when handling ctrl-c interrupt
63
- isTerminal * synx.Bool // Flag indicating if we are outputting to terminal
49
+ message * synx.String // message to display
50
+ stopChan chan struct {} // exit channel
51
+ speedUpdated * synx.Bool // Indicates speed has been updated
52
+ exitStatus status // Status of exit
53
+ successSymbol * synx.String // Symbol printed when Success() called
54
+ errorSymbol * synx.String // Symbol printed when Error() called
55
+ spinFrames * synx.StringSlice // Spinset frames
56
+ frameNumber int // Current frame [default 0]
57
+ termWidth * synx.Int // Terminal width
58
+ termHeight * synx.Int // Terminal Height
59
+ spinSpeed * synx.Int // Delay between spinner updates in milliseconds [default 100ms]
60
+ currentLine * synx.String // The current line being displayed
61
+ running * synx.Bool // Indicates if the spinner is running
62
+ abortMessage * synx.String // Printed when handling ctrl-c interrupt
63
+ isTerminal * synx.Bool // Flag indicating if we are outputting to terminal
64
+ exitOnInterrupt * synx.Bool // Indicates the spinner will os.Exit on interrupt
64
65
}
65
66
66
67
// NewSpinner creates a new spinner and sets up the default values.
@@ -72,19 +73,20 @@ func NewSpinner(optionalMessage ...string) *Spinner {
72
73
message = optionalMessage [0 ]
73
74
}
74
75
result := & Spinner {
75
- message : synx .NewString (message ),
76
- stopChan : make (chan struct {}),
77
- speedUpdated : synx .NewBool (true ),
78
- successSymbol : synx .NewString (successSymbol ),
79
- errorSymbol : synx .NewString (errorSymbol ),
80
- spinFrames : synx .NewStringSlice (getDefaultSpinnerFrames ()),
81
- spinSpeed : synx .NewInt (100 ),
82
- termWidth : synx .NewInt (1 ),
83
- termHeight : synx .NewInt (1 ),
84
- abortMessage : synx .NewString ("Aborted." ),
85
- frameNumber : 0 ,
86
- running : synx .NewBool (false ),
87
- isTerminal : synx .NewBool (isatty .IsTerminal (os .Stdout .Fd ())),
76
+ message : synx .NewString (message ),
77
+ stopChan : make (chan struct {}),
78
+ speedUpdated : synx .NewBool (true ),
79
+ successSymbol : synx .NewString (successSymbol ),
80
+ errorSymbol : synx .NewString (errorSymbol ),
81
+ spinFrames : synx .NewStringSlice (getDefaultSpinnerFrames ()),
82
+ spinSpeed : synx .NewInt (100 ),
83
+ termWidth : synx .NewInt (1 ),
84
+ termHeight : synx .NewInt (1 ),
85
+ abortMessage : synx .NewString ("Aborted." ),
86
+ frameNumber : 0 ,
87
+ running : synx .NewBool (false ),
88
+ isTerminal : synx .NewBool (isatty .IsTerminal (os .Stdout .Fd ())),
89
+ exitOnInterrupt : synx .NewBool (true ),
88
90
}
89
91
90
92
return result
@@ -187,14 +189,20 @@ func (s *Spinner) getRunning() bool {
187
189
func (s * Spinner ) setRunning (value bool ) {
188
190
s .running .SetValue (value )
189
191
}
192
+ func (s * Spinner ) getExitOnInterrupt () bool {
193
+ return s .exitOnInterrupt .GetValue ()
194
+ }
195
+
196
+ func (s * Spinner ) SetExitOnInterrupt (value bool ) {
197
+ s .exitOnInterrupt .SetValue (value )
198
+ }
190
199
191
200
func (s * Spinner ) printSuccess (message string , args ... interface {}) {
192
201
color .HiGreen (message , args ... )
193
202
}
194
203
195
204
// Start the spinner!
196
205
func (s * Spinner ) Start (optionalMessage ... string ) {
197
-
198
206
// If we're trying to start an already running spinner,
199
207
// add a slight delay and retry. This allows the spinner
200
208
// to complete a previous stop command gracefully.
@@ -232,7 +240,9 @@ func (s *Spinner) Start(optionalMessage ...string) {
232
240
s .stopChan <- struct {}{}
233
241
fmt .Println ("" )
234
242
color .HiRed ("\r %s %s" , s .getErrorSymbol (), s .getAbortMessage ())
235
- os .Exit (1 )
243
+ if s .getExitOnInterrupt () {
244
+ os .Exit (1 )
245
+ }
236
246
}(s .stopChan )
237
247
238
248
// spawn off a goroutine to handle the animation.
0 commit comments