1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package decor
var defaultSpinnerStyle = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
// Spinner returns spinner decorator.
//
// `frames` spinner frames, if nil or len==0, default is used
//
// `wcc` optional WC config
func Spinner(frames []string, wcc ...WC) Decorator {
var wc WC
for _, widthConf := range wcc {
wc = widthConf
}
if len(frames) == 0 {
frames = defaultSpinnerStyle
}
d := &spinnerDecorator{
WC: wc.Init(),
frames: frames,
}
return d
}
type spinnerDecorator struct {
WC
frames []string
count uint
}
func (d *spinnerDecorator) Decor(st *Statistics) string {
frame := d.frames[d.count%uint(len(d.frames))]
d.count++
return d.FormatMsg(frame)
}
|