/
spinner.go
55 lines (46 loc) · 891 Bytes
/
spinner.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package util
import (
"fmt"
"time"
"github.com/briandowns/spinner"
)
var (
quiet bool
spin *spinner.Spinner // There is only one spinner, output overlaps with multiple concurrent spinners
currentMessage string
isRunning bool
)
func init() {
// Note: don't set the colour here, it will display the spinner when you don't want it to
spin = spinner.New(spinner.CharSets[14], 100*time.Millisecond)
}
func SpinEnable(isEnabled bool) {
quiet = !isEnabled
}
func SpinStart(msg string) {
isRunning = true
currentMessage = msg
if quiet {
fmt.Println(msg)
return
}
_ = spin.Color("red")
spin.Stop()
spin.Suffix = " " + msg
spin.Start()
}
func SpinPause() bool {
wasRunning := isRunning
SpinStop()
return wasRunning
}
func SpinUnpause() {
SpinStart(currentMessage)
}
func SpinStop() {
isRunning = false
if quiet {
return
}
spin.Stop()
}