Debian Codegraph @

README.md

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 # Spinner
2
3 [![GoDoc](https://godoc.org/github.com/briandowns/spinner?status.svg)](https://godoc.org/github.com/briandowns/spinner) [![Build Status](https://travis-ci.org/briandowns/spinner.svg?branch=master)](https://travis-ci.org/briandowns/spinner)
4
5 spinner is a simple package to add a spinner / progress indicator to any terminal application. Examples can be found below as well as full examples in the examples directory.
6
7 For more detail about the library and its features, reference your local godoc once installed.
8
9 Contributions welcome!
10
11 ## Installation
12
13 ```bash
14 go get github.com/briandowns/spinner
15 ```
16
17 ## Available Character Sets
18
19 90 Character Sets. Some examples below:
20
21 (Numbered by their slice index)
22
23 | index | character set | sample gif |
24 | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- |
25 | 0 | ```←↖↑↗→↘↓↙``` | ![Sample Gif](gifs/0.gif) |
26 | 1 | ```▁▃▄▅▆▇█▇▆▅▄▃▁``` | ![Sample Gif](gifs/1.gif) |
27 | 2 | ```▖▘▝▗``` | ![Sample Gif](gifs/2.gif) |
28 | 3 | ```┤┘┴└├┌┬┐``` | ![Sample Gif](gifs/3.gif) |
29 | 4 | ```◢◣◤◥``` | ![Sample Gif](gifs/4.gif) |
30 | 5 | ```◰◳◲◱``` | ![Sample Gif](gifs/5.gif) |
31 | 6 | ```◴◷◶◵``` | ![Sample Gif](gifs/6.gif) |
32 | 7 | ```◐◓◑◒``` | ![Sample Gif](gifs/7.gif) |
33 | 8 | ```.oO@*``` | ![Sample Gif](gifs/8.gif) |
34 | 9 | ```\|/-\``` | ![Sample Gif](gifs/9.gif) |
35 | 10 | ```◡◡⊙⊙◠◠``` | ![Sample Gif](gifs/10.gif) |
36 | 11 | ```⣾⣽⣻⢿⡿⣟⣯⣷``` | ![Sample Gif](gifs/11.gif) |
37 | 12 | ```>))'> >))'> >))'> >))'> >))'> <'((< <'((< <'((<``` | ![Sample Gif](gifs/12.gif) |
38 | 13 | ```⠁⠂⠄⡀⢀⠠⠐⠈``` | ![Sample Gif](gifs/13.gif) |
39 | 14 | ```⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏``` | ![Sample Gif](gifs/14.gif) |
40 | 15 | ```abcdefghijklmnopqrstuvwxyz``` | ![Sample Gif](gifs/15.gif) |
41 | 16 | ```▉▊▋▌▍▎▏▎▍▌▋▊▉``` | ![Sample Gif](gifs/16.gif) |
42 | 17 | ```■□▪▫``` | ![Sample Gif](gifs/17.gif) |
43 | 18 | ```←↑→↓``` | ![Sample Gif](gifs/18.gif) |
44 | 19 | ```╫╪``` | ![Sample Gif](gifs/19.gif) |
45 | 20 | ```⇐⇖⇑⇗⇒⇘⇓⇙``` | ![Sample Gif](gifs/20.gif) |
46 | 21 | ```⠁⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈⠈``` | ![Sample Gif](gifs/21.gif) |
47 | 22 | ```⠈⠉⠋⠓⠒⠐⠐⠒⠖⠦⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈``` | ![Sample Gif](gifs/22.gif) |
48 | 23 | ```⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠴⠲⠒⠂⠂⠒⠚⠙⠉⠁``` | ![Sample Gif](gifs/23.gif) |
49 | 24 | ```⠋⠙⠚⠒⠂⠂⠒⠲⠴⠦⠖⠒⠐⠐⠒⠓⠋``` | ![Sample Gif](gifs/24.gif) |
50 | 25 | ```ヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン``` | ![Sample Gif](gifs/25.gif) |
51 | 26 | ```. .. ...``` | ![Sample Gif](gifs/26.gif) |
52 | 27 | ```▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▏▎▍▌▋▊▉█▇▆▅▄▃▂▁``` | ![Sample Gif](gifs/27.gif) |
53 | 28 | ```.oO°Oo.``` | ![Sample Gif](gifs/28.gif) |
54 | 29 | ```+x``` | ![Sample Gif](gifs/29.gif) |
55 | 30 | ```v<^>``` | ![Sample Gif](gifs/30.gif) |
56 | 31 | ```>>---> >>---> >>---> >>---> >>---> <---<< <---<< <---<< <---<< <---<<``` | ![Sample Gif](gifs/31.gif) |
57 | 32 | ```\| \|\| \|\|\| \|\|\|\| \|\|\|\|\| \|\|\|\|\|\| \|\|\|\|\| \|\|\|\| \|\|\| \|\| \|``` | ![Sample Gif](gifs/32.gif) |
58 | 33 | ```[] [=] [==] [===] [====] [=====] [======] [=======] [========] [=========] [==========]``` | ![Sample Gif](gifs/33.gif) |
59 | 34 | ```(*---------) (-*--------) (--*-------) (---*------) (----*-----) (-----*----) (------*---) (-------*--) (--------*-) (---------*)``` | ![Sample Gif](gifs/34.gif) |
60 | 35 | ```█▒▒▒▒▒▒▒▒▒ ███▒▒▒▒▒▒▒ █████▒▒▒▒▒ ███████▒▒▒ ██████████``` | ![Sample Gif](gifs/35.gif) |
61 | 36 | ```[ ] [=> ] [===> ] [=====> ] [======> ] [========> ] [==========> ] [============> ] [==============> ] [================> ] [==================> ] [===================>]``` | ![Sample Gif](gifs/36.gif) |
62 | 37 | ```🕐 🕑 🕒 🕓 🕔 🕕 🕖 🕗 🕘 🕙 🕚 🕛``` | ![Sample Gif](gifs/37.gif) |
63 | 38 | ```🕐 🕜 🕑 🕝 🕒 🕞 🕓 🕟 🕔 🕠 🕕 🕡 🕖 🕢 🕗 🕣 🕘 🕤 🕙 🕥 🕚 🕦 🕛 🕧``` | ![Sample Gif](gifs/38.gif) |
64 | 39 | ```🌍 🌎 🌏``` | ![Sample Gif](gifs/39.gif) |
65 | 40 | ```◜ ◝ ◞ ◟``` | ![Sample Gif](gifs/40.gif) |
66 | 41 | ```⬒ ⬔ ⬓ ⬕``` | ![Sample Gif](gifs/41.gif) |
67 | 42 | ```⬖ ⬘ ⬗ ⬙``` | ![Sample Gif](gifs/42.gif) |
68 | 43 | ```[>>> >] []>>>> [] [] >>>> [] [] >>>> [] [] >>>> [] [] >>>>[] [>> >>]``` | ![Sample Gif](gifs/43.gif) |
69
70 ## Features
71
72 * Start
73 * Stop
74 * Restart
75 * Reverse direction
76 * Update the spinner character set
77 * Update the spinner speed
78 * Prefix or append text
79 * Change spinner color, background, and text attributes such as bold / italics
80 * Get spinner status
81 * Chain, pipe, redirect output
82 * Output final string on spinner/indicator completion
83
84 ## Examples
85
86 ```Go
87 package main
88
89 import (
90 "github.com/briandowns/spinner"
91 "time"
92 )
93
94 func main() {
95 s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) // Build our new spinner
96 s.Start() // Start the spinner
97 time.Sleep(4 * time.Second) // Run for some time to simulate work
98 s.Stop()
99 }
100 ```
101
102 ## Update the character set and restart the spinner
103
104 ```Go
105 s.UpdateCharSet(spinner.CharSets[1]) // Update spinner to use a different character set
106 s.Restart() // Restart the spinner
107 time.Sleep(4 * time.Second)
108 s.Stop()
109 ```
110
111 ## Update spin speed and restart the spinner
112
113 ```Go
114 s.UpdateSpeed(200 * time.Millisecond) // Update the speed the spinner spins at
115 s.Restart()
116 time.Sleep(4 * time.Second)
117 s.Stop()
118 ```
119
120 ## Reverse the direction of the spinner
121
122 ```Go
123 s.Reverse() // Reverse the direction the spinner is spinning
124 s.Restart()
125 time.Sleep(4 * time.Second)
126 s.Stop()
127 ```
128
129 ## Provide your own spinner
130
131 (or send me an issue or pull request to add to the project)
132
133 ```Go
134 someSet := []string{"+", "-"}
135 s := spinner.New(someSet, 100*time.Millisecond)
136 ```
137
138 ## Prefix or append text to the spinner
139
140 ```Go
141 s.Prefix = "prefixed text: " // Prefix text before the spinner
142 s.Suffix = " :appended text" // Append text after the spinner
143 ```
144
145 ## Set or change the color of the spinner. Default color is white. The spinner will need to be restarted to pick up the change.
146
147 ```Go
148 s.Color("red") // Set the spinner color to red
149 ```
150
151 You can specify both the background and foreground color, as well as additional attributes such as `bold` or `underline`.
152
153 ```Go
154 s.Color("red", "bold") // Set the spinner color to a bold red
155 ```
156
157 To set the background to black, the foreground to a bold red:
158
159 ```Go
160 s.Color("bgBlack", "bold", "fgRed")
161 ```
162
163 Below is the full color and attribute list:
164
165 ```Go
166 // default colors
167 red
168 black
169 green
170 yellow
171 blue
172 magenta
173 cyan
174 white
175
176 // attributes
177 reset
178 bold
179 faint
180 italic
181 underline
182 blinkslow
183 blinkrapid
184 reversevideo
185 concealed
186 crossedout
187
188 // foreground text
189 fgBlack
190 fgRed
191 fgGreen
192 fgYellow
193 fgBlue
194 fgMagenta
195 fgCyan
196 fgWhite
197
198 // foreground Hi-Intensity text
199 fgHiBlack
200 fgHiRed
201 fgHiGreen
202 fgHiYellow
203 fgHiBlue
204 fgHiMagenta
205 fgHiCyan
206 fgHiWhite
207
208 // background text
209 bgBlack
210 bgRed
211 bgGreen
212 bgYellow
213 bgBlue
214 bgMagenta
215 bgCyan
216 bgWhite
217
218 // background Hi-Intensity text
219 bgHiBlack
220 bgHiRed
221 bgHiGreen
222 bgHiYellow
223 bgHiBlue
224 bgHiMagenta
225 bgHiCyan
226 bgHiWhite
227 ```
228
229 ## Generate a sequence of numbers
230
231 ```Go
232 setOfDigits := spinner.GenerateNumberSequence(25) // Generate a 25 digit string of numbers
233 s := spinner.New(setOfDigits, 100*time.Millisecond)
234 ```
235
236 ## Get spinner status
237
238 ```Go
239 fmt.Println(s.Active())
240 ```
241
242 ## Unix pipe and redirect
243
244 Feature suggested and write up by [dekz](https://github.com/dekz)
245
246 Setting the Spinner Writer to Stderr helps show progress to the user, with the enhancement to chain, pipe or redirect the output.
247
248 This is the preferred method of setting a Writer at this time.
249
250 ```go
251 s := spinner.New(spinner.CharSets[11], 100*time.Millisecond, spinner.WithWriter(os.Stderr))
252 s.Suffix = " Encrypting data..."
253 s.Start()
254 // Encrypt the data into ciphertext
255 fmt.Println(os.Stdout, ciphertext)
256 ```
257
258 ```sh
259 > myprog encrypt "Secret text" > encrypted.txt
260 ⣯ Encrypting data...
261 ```
262
263 ```sh
264 > cat encrypted.txt
265 1243hjkbas23i9ah27sj39jghv237n2oa93hg83
266 ```
267
268 ## Final String Output
269
270 Add additional output when the spinner/indicator has completed. The "final" output string can be multi-lined and will be written to wherever the `io.Writer` has been configured for.
271
272 ```Go
273 s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
274 s.FinalMSG = "Complete!\nNew line!\nAnother one!\n"
275 s.Start()
276 time.Sleep(4 * time.Second)
277 s.Stop()
278 ```
279
280 Output
281 ```sh
282 Complete!
283 New line!
284 Another one!
285 ```