/
spinner.go
48 lines (39 loc) · 831 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
package ui
import (
"time"
"github.com/briandowns/spinner"
)
// Spinner struct contains the spinner struct and display text
type Spinner struct {
spinner *spinner.Spinner
text string
enabled bool
}
// newSpinner creates a new Spinner struct
func newSpinner(text string, enabled bool) *Spinner {
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.Suffix = " " + text
return &Spinner{
s,
text,
enabled,
}
}
// Start displays the Spinner and starts movement
func (s *Spinner) Start() {
if !s.enabled {
return
}
s.spinner.Start()
}
// Stop halts the spiner movement and removes it from display
func (s *Spinner) Stop() {
if !s.enabled {
return
}
s.spinner.Stop()
}
// Update changes the Spinner's suffix to 'text'
func (s *Spinner) Update(text string) {
s.spinner.Suffix = " " + text
}