forked from railwayapp/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspinner.go
More file actions
52 lines (41 loc) · 1.46 KB
/
Copy pathspinner.go
File metadata and controls
52 lines (41 loc) · 1.46 KB
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
package ui
import (
"os"
"time"
"github.com/briandowns/spinner"
)
type TrainSpinner []string
var (
TrainRight TrainSpinner = []string{"🚅", "🚅🚋", "🚅🚋🚋", "🚅🚋🚋🚋", "🚅🚋🚋🚋🚋", "🚅🚋🚋🚋🚋🚋", "🚅🚋🚋🚋🚋🚋🚋", "🚅🚋🚋🚋🚋🚋🚋🚋", "🚅🚋🚋🚋🚋🚋🚋🚋🚋"}
TrainLeft TrainSpinner = []string{" 🚅", " 🚅🚋", " 🚅🚋🚋", " 🚅🚋🚋🚋", " 🚅🚋🚋🚋🚋", " 🚅🚋🚋🚋🚋🚋", " 🚅🚋🚋🚋🚋🚋🚋", " 🚅🚋🚋🚋🚋🚋🚋🚋", "🚅🚋🚋🚋🚋🚋🚋🚋🚋"}
TrainEmojis TrainSpinner = []string{"🚝", "🚅", "🚄", "🚇", "🚞", "🚈", "🚉", "🚂", "🚃", "🚊", "🚋"}
)
type SpinnerCfg struct {
// Message specifies the text label that appears while loading
Message string
// Tokens is a list of emoji to rotate through, during loading
Tokens []string
// Duration is the amount of delay between each spinner "frame"
Duration time.Duration
}
var s = &spinner.Spinner{}
func StartSpinner(cfg *SpinnerCfg) {
if cfg.Tokens == nil {
cfg.Tokens = TrainEmojis
}
if cfg.Duration.Microseconds() == 0 {
cfg.Duration = time.Duration(100) * time.Millisecond
}
s = spinner.New(cfg.Tokens, cfg.Duration)
s.Writer = os.Stdout
if cfg.Message != "" {
s.Suffix = " " + cfg.Message
}
s.Start()
}
func StopSpinner(msg string) {
if msg != "" {
s.FinalMSG = msg + "\n"
}
s.Stop()
}