@@ -26,7 +26,9 @@ import (
26
26
"os"
27
27
"strconv"
28
28
"strings"
29
+ "time"
29
30
31
+ "github.com/briandowns/spinner"
30
32
isatty "github.com/mattn/go-isatty"
31
33
32
34
"k8s.io/klog/v2"
@@ -58,10 +60,14 @@ var (
58
60
OverrideEnv = "MINIKUBE_IN_STYLE"
59
61
// JSON is whether or not we should output stdout in JSON format. Set using SetJSON()
60
62
JSON = false
63
+ // spin is spinner showed at starting minikube
64
+ spin = spinner .New (spinner .CharSets [style .SpinnerCharacter ], 100 * time .Millisecond )
61
65
)
62
66
63
67
// MaxLogEntries controls the number of log entries to show for each source
64
- const MaxLogEntries = 3
68
+ const (
69
+ MaxLogEntries = 3
70
+ )
65
71
66
72
// fdWriter is the subset of file.File that implements io.Writer and Fd()
67
73
type fdWriter interface {
@@ -78,18 +84,22 @@ func Step(st style.Enum, format string, a ...V) {
78
84
Infof (format , a ... )
79
85
return
80
86
}
81
- outStyled := stylized (st , useColor , format , a ... )
87
+ outStyled , spinner := stylized (st , useColor , format , a ... )
82
88
if JSON {
83
89
register .PrintStep (outStyled )
84
90
return
85
91
}
86
92
register .RecordStep (outStyled )
87
- String (outStyled )
93
+ if spinner {
94
+ spinnerString (outStyled )
95
+ } else {
96
+ String (outStyled )
97
+ }
88
98
}
89
99
90
100
// Infof is used for informational logs (options, env variables, etc)
91
101
func Infof (format string , a ... V ) {
92
- outStyled := stylized (style .Option , useColor , format , a ... )
102
+ outStyled , _ := stylized (style .Option , useColor , format , a ... )
93
103
if JSON {
94
104
register .PrintInfo (outStyled )
95
105
return
@@ -106,13 +116,34 @@ func String(format string, a ...interface{}) {
106
116
klog .Warningf ("[unset outFile]: %s" , fmt .Sprintf (format , a ... ))
107
117
return
108
118
}
109
-
110
119
klog .Infof (format , a ... )
120
+ // if spin is active from a previous step, it will stop spinner displaying
121
+ if spin .Active () {
122
+ spin .Stop ()
123
+ }
124
+ _ , err := fmt .Fprintf (outFile , format , a ... )
125
+ if err != nil {
126
+ klog .Errorf ("Fprintf failed: %v" , err )
127
+ }
128
+ }
111
129
130
+ // spinnerString writes a basic formatted string to stdout with spinner character
131
+ func spinnerString (format string , a ... interface {}) {
132
+ // Flush log buffer so that output order makes sense
133
+ klog .Flush ()
134
+
135
+ if outFile == nil {
136
+ klog .Warningf ("[unset outFile]: %s" , fmt .Sprintf (format , a ... ))
137
+ return
138
+ }
139
+
140
+ klog .Infof (format , a ... )
112
141
_ , err := fmt .Fprintf (outFile , format , a ... )
113
142
if err != nil {
114
143
klog .Errorf ("Fprintf failed: %v" , err )
115
144
}
145
+ // Start spinning at the end of the printed line
146
+ spin .Start ()
116
147
}
117
148
118
149
// Ln writes a basic formatted string with a newline to stdout
@@ -126,7 +157,7 @@ func Ln(format string, a ...interface{}) {
126
157
127
158
// ErrT writes a stylized and templated error message to stderr
128
159
func ErrT (st style.Enum , format string , a ... V ) {
129
- errStyled := stylized (st , useColor , format , a ... )
160
+ errStyled , _ := stylized (st , useColor , format , a ... )
130
161
Err (errStyled )
131
162
}
132
163
@@ -169,7 +200,8 @@ func FatalT(format string, a ...V) {
169
200
// WarningT is a shortcut for writing a templated warning message to stderr
170
201
func WarningT (format string , a ... V ) {
171
202
if JSON {
172
- register .PrintWarning (stylized (style .Warning , useColor , format , a ... ))
203
+ st , _ := stylized (style .Warning , useColor , format , a ... )
204
+ register .PrintWarning (st )
173
205
return
174
206
}
175
207
ErrT (style .Warning , format , a ... )
0 commit comments