File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
+ "errors"
4
5
"fmt"
5
6
"time"
6
7
@@ -16,10 +17,17 @@ func main() {
16
17
s .Stop ()
17
18
18
19
fmt .Println ()
19
- // Run with another template
20
+ // Run with another template and success message
20
21
sp := spinner .New ("Loading..." )
21
22
sp .SetTemplate (template .Arrow )
22
23
sp .Start ()
23
24
time .Sleep (time .Second * 2 )
24
- sp .Stop ()
25
+ sp .Success ("Success" )
26
+
27
+ fmt .Println ()
28
+ // Run with error message
29
+ spi := spinner .New ("Loading..." )
30
+ spi .Start ()
31
+ time .Sleep (time .Second * 2 )
32
+ spi .Error (errors .New ("error to load" ))
25
33
}
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package spinner
3
3
import (
4
4
"fmt"
5
5
"io"
6
+ "runtime"
6
7
"sync"
7
8
"syscall"
8
9
"time"
@@ -56,7 +57,14 @@ func StartNew(title string) *Spinner {
56
57
57
58
// Start starts the spinner execution
58
59
func (s * Spinner ) Start () * Spinner {
60
+ goos := runtime .GOOS
61
+ if goos == "windows" { // Show title without animation on Windows
62
+ fmt .Print (s .Title )
63
+ return s
64
+ }
65
+
59
66
go s .writer ()
67
+
60
68
return s
61
69
}
62
70
@@ -90,13 +98,13 @@ func (s *Spinner) Stop() {
90
98
// Success gives success feedback for users and stops the spinner execution
91
99
func (s * Spinner ) Success (msg string ) {
92
100
s .Stop ()
93
- fmt .Println ( msg )
101
+ fmt .Printf ( " \r %s \n " , msg )
94
102
}
95
103
96
104
// Error gives error feedback for users and stops the spinner execution
97
105
func (s * Spinner ) Error (err error ) {
98
106
s .Stop ()
99
- fmt .Println ( err )
107
+ fmt .Printf ( " \r %s \n " , err )
100
108
}
101
109
102
110
// animate runs the template animation
You can’t perform that action at this time.
0 commit comments