๐Ÿ“š spinner - Awesome Go Library for Command Line

Go Gopher mascot for spinner

Go package to easily provide a terminal spinner with options.

๐Ÿท๏ธ Command Line
๐Ÿ“‚ Libraries for building Console Applications and Console User Interfaces.
โญ 2,333 stars
View on GitHub ๐Ÿ”—

Detailed Description of spinner

Spinner

GoDoc CircleCI

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.

For more detail about the library and its features, reference your local godoc once installed.

Contributions welcome!

Installation

go get github.com/briandowns/spinner

Available Character Sets

90 Character Sets. Some examples below:

(Numbered by their slice index)

indexcharacter setsample gif
0โ†โ†–โ†‘โ†—โ†’โ†˜โ†“โ†™Sample Gif
1โ–โ–ƒโ–„โ–…โ–†โ–‡โ–ˆโ–‡โ–†โ–…โ–„โ–ƒโ–Sample Gif
2โ––โ–˜โ–โ–—Sample Gif
3โ”คโ”˜โ”ดโ””โ”œโ”Œโ”ฌโ”Sample Gif
4โ—ขโ—ฃโ—คโ—ฅSample Gif
5โ—ฐโ—ณโ—ฒโ—ฑSample Gif
6โ—ดโ—ทโ—ถโ—ตSample Gif
7โ—โ—“โ—‘โ—’Sample Gif
8.oO@*Sample Gif
9|/-\Sample Gif
10โ—กโ—กโŠ™โŠ™โ— โ— Sample Gif
11โฃพโฃฝโฃปโขฟโกฟโฃŸโฃฏโฃทSample Gif
12>))'> >))'> >))'> >))'> >))'> <'((< <'((< <'((<Sample Gif
13โ โ ‚โ „โก€โข€โ  โ โ ˆSample Gif
14โ ‹โ ™โ นโ ธโ ผโ ดโ ฆโ งโ ‡โ Sample Gif
15abcdefghijklmnopqrstuvwxyzSample Gif
16โ–‰โ–Šโ–‹โ–Œโ–โ–Žโ–โ–Žโ–โ–Œโ–‹โ–Šโ–‰Sample Gif
17โ– โ–กโ–ชโ–ซSample Gif
18โ†โ†‘โ†’โ†“Sample Gif
19โ•ซโ•ชSample Gif
20โ‡โ‡–โ‡‘โ‡—โ‡’โ‡˜โ‡“โ‡™Sample Gif
21โ โ โ ‰โ ™โ šโ ’โ ‚โ ‚โ ’โ ฒโ ดโ คโ „โ „โ คโ  โ  โ คโ ฆโ –โ ’โ โ โ ’โ “โ ‹โ ‰โ ˆโ ˆSample Gif
22โ ˆโ ‰โ ‹โ “โ ’โ โ โ ’โ –โ ฆโ คโ  โ  โ คโ ฆโ –โ ’โ โ โ ’โ “โ ‹โ ‰โ ˆSample Gif
23โ โ ‰โ ™โ šโ ’โ ‚โ ‚โ ’โ ฒโ ดโ คโ „โ „โ คโ ดโ ฒโ ’โ ‚โ ‚โ ’โ šโ ™โ ‰โ Sample Gif
24โ ‹โ ™โ šโ ’โ ‚โ ‚โ ’โ ฒโ ดโ ฆโ –โ ’โ โ โ ’โ “โ ‹Sample Gif
25๏ฝฆ๏ฝง๏ฝจ๏ฝฉ๏ฝช๏ฝซ๏ฝฌ๏ฝญ๏ฝฎ๏ฝฏ๏ฝฑ๏ฝฒ๏ฝณ๏ฝด๏ฝต๏ฝถ๏ฝท๏ฝธ๏ฝน๏ฝบ๏ฝป๏ฝผ๏ฝฝ๏ฝพ๏ฝฟ๏พ€๏พ๏พ‚๏พƒ๏พ„๏พ…๏พ†๏พ‡๏พˆ๏พ‰๏พŠ๏พ‹๏พŒ๏พ๏พŽ๏พ๏พ๏พ‘๏พ’๏พ“๏พ”๏พ•๏พ–๏พ—๏พ˜๏พ™๏พš๏พ›๏พœ๏พSample Gif
26. .. ...Sample Gif
27โ–โ–‚โ–ƒโ–„โ–…โ–†โ–‡โ–ˆโ–‰โ–Šโ–‹โ–Œโ–โ–Žโ–โ–โ–Žโ–โ–Œโ–‹โ–Šโ–‰โ–ˆโ–‡โ–†โ–…โ–„โ–ƒโ–‚โ–Sample Gif
28.oOยฐOo.Sample Gif
29+xSample Gif
30v<^>Sample Gif
31>>---> >>---> >>---> >>---> >>---> <---<< <---<< <---<< <---<< <---<<Sample Gif
32| || ||| |||| ||||| |||||| ||||| |||| ||| || |Sample Gif
33[] [=] [==] [===] [====] [=====] [======] [=======] [========] [=========] [==========]Sample Gif
34(*---------) (-*--------) (--*-------) (---*------) (----*-----) (-----*----) (------*---) (-------*--) (--------*-) (---------*)Sample Gif
35โ–ˆโ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’ โ–ˆโ–ˆโ–ˆโ–’โ–’โ–’โ–’โ–’โ–’โ–’ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–’โ–’โ–’โ–’โ–’ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–’โ–’โ–’ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆSample Gif
36[ ] [=> ] [===> ] [=====> ] [======> ] [========> ] [==========> ] [============> ] [==============> ] [================> ] [==================> ] [===================>]Sample Gif
37๐Ÿ• ๐Ÿ•‘ ๐Ÿ•’ ๐Ÿ•“ ๐Ÿ•” ๐Ÿ•• ๐Ÿ•– ๐Ÿ•— ๐Ÿ•˜ ๐Ÿ•™ ๐Ÿ•š ๐Ÿ•›Sample Gif
38๐Ÿ• ๐Ÿ•œ ๐Ÿ•‘ ๐Ÿ• ๐Ÿ•’ ๐Ÿ•ž ๐Ÿ•“ ๐Ÿ•Ÿ ๐Ÿ•” ๐Ÿ•  ๐Ÿ•• ๐Ÿ•ก ๐Ÿ•– ๐Ÿ•ข ๐Ÿ•— ๐Ÿ•ฃ ๐Ÿ•˜ ๐Ÿ•ค ๐Ÿ•™ ๐Ÿ•ฅ ๐Ÿ•š ๐Ÿ•ฆ ๐Ÿ•› ๐Ÿ•งSample Gif
39๐ŸŒ ๐ŸŒŽ ๐ŸŒSample Gif
40โ—œ โ— โ—ž โ—ŸSample Gif
41โฌ’ โฌ” โฌ“ โฌ•Sample Gif
42โฌ– โฌ˜ โฌ— โฌ™Sample Gif
43[>>> >] []>>>> [] [] >>>> [] [] >>>> [] [] >>>> [] [] >>>>[] [>> >>]Sample Gif

Features

  • Start
  • Stop
  • Restart
  • Reverse direction
  • Update the spinner character set
  • Update the spinner speed
  • Prefix or append text
  • Change spinner color, background, and text attributes such as bold / italics
  • Get spinner status
  • Chain, pipe, redirect output
  • Output final string on spinner/indicator completion

Examples

package main

import (
	"github.com/briandowns/spinner"
	"time"
)

func main() {
	s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)  // Build our new spinner
	s.Start()                                                    // Start the spinner
	time.Sleep(4 * time.Second)                                  // Run for some time to simulate work
	s.Stop()
}

Update the character set and restart the spinner

s.UpdateCharSet(spinner.CharSets[1])  // Update spinner to use a different character set
s.Restart()                           // Restart the spinner
time.Sleep(4 * time.Second)
s.Stop()

Update spin speed and restart the spinner

s.UpdateSpeed(200 * time.Millisecond) // Update the speed the spinner spins at
s.Restart()
time.Sleep(4 * time.Second)
s.Stop()

Reverse the direction of the spinner

s.Reverse() // Reverse the direction the spinner is spinning
s.Restart()
time.Sleep(4 * time.Second)
s.Stop()

Provide your own spinner

(or send me an issue or pull request to add to the project)

someSet := []string{"+", "-"}
s := spinner.New(someSet, 100*time.Millisecond)

Prefix or append text to the spinner

s.Prefix = "prefixed text: " // Prefix text before the spinner
s.Suffix = "  :appended text" // Append text after the spinner

Set or change the color of the spinner. Default color is white. The spinner will need to be restarted to pick up the change.

s.Color("red") // Set the spinner color to red

You can specify both the background and foreground color, as well as additional attributes such as bold or underline.

s.Color("red", "bold") // Set the spinner color to a bold red

To set the background to black, the foreground to a bold red:

s.Color("bgBlack", "bold", "fgRed")

Below is the full color and attribute list:

// default colors
red
black
green
yellow
blue
magenta
cyan
white

// attributes
reset
bold
faint
italic
underline
blinkslow
blinkrapid
reversevideo
concealed
crossedout

// foreground text
fgBlack
fgRed
fgGreen
fgYellow
fgBlue
fgMagenta
fgCyan
fgWhite

// foreground Hi-Intensity text
fgHiBlack
fgHiRed
fgHiGreen
fgHiYellow
fgHiBlue
fgHiMagenta
fgHiCyan
fgHiWhite

// background text
bgBlack
bgRed
bgGreen
bgYellow
bgBlue
bgMagenta
bgCyan
bgWhite

// background Hi-Intensity text
bgHiBlack
bgHiRed
bgHiGreen
bgHiYellow
bgHiBlue
bgHiMagenta
bgHiCyan
bgHiWhite

Generate a sequence of numbers

setOfDigits := spinner.GenerateNumberSequence(25)    // Generate a 25 digit string of numbers
s := spinner.New(setOfDigits, 100*time.Millisecond)

Get spinner status

fmt.Println(s.Active())

Unix pipe and redirect

Feature suggested and write up by dekz

Setting the Spinner Writer to Stderr helps show progress to the user, with the enhancement to chain, pipe or redirect the output.

This is the preferred method of setting a Writer at this time.

s := spinner.New(spinner.CharSets[11], 100*time.Millisecond, spinner.WithWriter(os.Stderr))
s.Suffix = " Encrypting data..."
s.Start()
// Encrypt the data into ciphertext
fmt.Println(os.Stdout, ciphertext)
> myprog encrypt "Secret text" > encrypted.txt
โฃฏ Encrypting data...
> cat encrypted.txt
1243hjkbas23i9ah27sj39jghv237n2oa93hg83

Final String Output

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.

s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.FinalMSG = "Complete!\nNew line!\nAnother one!\n"
s.Start()                 
time.Sleep(4 * time.Second)
s.Stop()                   

Output

Complete!
New line!
Another one!