-
Notifications
You must be signed in to change notification settings - Fork 129
/
main.go
112 lines (78 loc) · 2.72 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Example application that uses all of the available API options.
package main
import (
"log"
"strings"
"time"
"github.com/briandowns/spinner"
)
func main() {
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) // Build our new spinner
s.Color("red") // Set the spinner color to red
s.Start() // Start the spinner
time.Sleep(4 * time.Second) // Run for some time to simulate work
s.UpdateCharSet(spinner.CharSets[9]) // Update spinner to use a different character set
s.UpdateSpeed(100 * time.Millisecond) // Update the speed the spinner spins at
s.Prefix = "prefixed text: " // Prefix text before the spinner
time.Sleep(4 * time.Second)
s.Prefix = ""
s.Suffix = " :appended text" // Append text after the spinner
time.Sleep(4 * time.Second)
s.Suffix = " :appended " + strings.Repeat("very long text ", 20) // Append very long text
time.Sleep(4 * time.Second)
s.Suffix = " :appended multi \nline\nsuffix\ntext" // Append multi line text
time.Sleep(4 * time.Second)
s.Suffix = " :appended text" // Append text after the spinner
s.Prefix = "Colors: "
if err := s.Color("yellow"); err != nil {
log.Fatalln(err)
}
s.Start()
time.Sleep(4 * time.Second) // Run for some time to simulate work
if err := s.Color("red"); err != nil {
log.Fatalln(err)
}
s.UpdateCharSet(spinner.CharSets[20])
s.Reverse()
s.Restart()
time.Sleep(4 * time.Second) // Run for some time to simulate work
if err := s.Color("blue"); err != nil {
log.Fatalln(err)
}
s.UpdateCharSet(spinner.CharSets[3])
s.Restart()
time.Sleep(4 * time.Second) // Run for some time to simulate work
if err := s.Color("cyan"); err != nil {
log.Fatalln(err)
}
s.UpdateCharSet(spinner.CharSets[28])
s.Reverse()
s.Restart()
time.Sleep(4 * time.Second) // Run for some time to simulate work
if err := s.Color("green"); err != nil {
log.Fatalln(err)
}
s.UpdateCharSet(spinner.CharSets[25])
s.Restart()
time.Sleep(4 * time.Second) // Run for some time to simulate work
if err := s.Color("magenta"); err != nil {
log.Fatalln(err)
}
s.UpdateCharSet(spinner.CharSets[32])
s.Restart()
time.Sleep(4 * time.Second) // Run for some time to simulate work
if err := s.Color("white"); err != nil {
log.Fatalln(err)
}
s.FinalMSG = "Complete!\nNew line!\nAnother one!\n"
s.UpdateCharSet(spinner.CharSets[31])
s.Restart()
time.Sleep(4 * time.Second) // Run for some time to simulate work
s.Stop() // Stop the spinner
s.Prefix = "Earth! "
s.UpdateCharSet(spinner.CharSets[39])
s.Restart()
time.Sleep(4 * time.Second) // Run for some time to simulate work
s.Stop() // Stop the spinner
println("")
}