• Stars
    star
    2,150
  • Rank 20,595 (Top 0.5 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go (golang) package with 90 configurable terminal spinner/progress indicators.

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)

index character set sample 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
15 abcdefghijklmnopqrstuvwxyz Sample 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 +x Sample Gif
30 v<^> 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!

More Repositories

1

simple-httpd

Drop-in replacement for Python SimpleHTTPServer. Provides TLS via Let's Encrypt over HTTP2, and auto generated self-signed certificates.
Go
230
star
2

openweathermap

Go (golang) package for use with openweathermap.org's API.
Go
224
star
3

sky-island

FaaS platform for running raw Go functions.
Go
116
star
4

super-hacker

SuperHacker is the ultimate utility to make you look like a hacker.
Go
49
star
5

jail

Package jail provides native FreeBSD Jail syscalls in Go
Go
48
star
6

remindme

Go
28
star
7

todo-view

Extract info from TODO's in your code from formatted TODO comments
Go
27
star
8

liblogger

A simple and performant, single-header JSON structured logger for C applications.
C
15
star
9

GoPasswordUtilities

Simple library for working with passwords in Go (golang).
Go
13
star
10

flotsam

Project Generator and Dependency Manager for C.
C++
11
star
11

pass

Simple CLI Password Manager
C
11
star
12

heads-up

A simple example of using Tile38 to track the ISS and send notifications when it's overhead.
Go
10
star
13

simple-map

A simple and dynamic hash map in C.
C++
10
star
14

presentations

Public repo for my slides
Go
9
star
15

stockwatcher

A CLI application to monitor one or more stocks.
Go
7
star
16

smile

Smile. Why not?
Go
7
star
17

struCtured-logger

A simple JSON structured logger for C applications.
C++
6
star
18

recipes

A collection of recipes I've created, found, and have been given.
6
star
19

raceway

OpenStack Rally Job Controller
Go
6
star
20

roam-client

Roam by Tile38 API Client
Go
6
star
21

cgo_calc

IGNORE. Meant as a descripton of some tech for ${DAY_JOB}
Go
5
star
22

neustar

Package neustar is a SDK to access and work with the Neustar API
Go
5
star
23

nlog

Structured Logging for Nim
Nim
5
star
24

libmap

A simple map implementation in C
C
5
star
25

libdotenv

libdotenv is a C single-headerlibrary providing the ability to load values from a .env file into environment variables.
C
4
star
26

aion

WIP - Job and Task Scheduler Utilizing Cron Syntax
Go
4
star
27

ip

Go
4
star
28

libweyl

Middle Random Weyl Sequence
C++
4
star
29

pyopenvswitch

Python module to control and interact with Open vSwitch switches.
Python
2
star
30

doom-fire-c

C
2
star
31

stock-exchange

Go
2
star
32

libbenchmark

loads is a simple library to benchmark C functions across a given number of threads.
C++
2
star
33

down-low

down-low is a secure messaging system written in Go (golang) with the ability to send AES and RSA encrypted messages to a number of different endpoints.
Go
2
star
34

mapledb

2
star
35

games

Terminal games written in Go (golang)
Go
2
star
36

wanbli

1
star
37

gen-release-notes

Go
1
star
38

vms

Shell
1
star
39

kahless

Makefile
1
star
40

gail

Go
1
star
41

jail-builder

Go
1
star
42

logcolor

Go
1
star
43

dictu_modules

C
1
star
44

daily_tracker

C
1
star
45

anagram-primes

C
1
star
46

formatifier

formatifier is a Go (golang) package to quickly format strings in common formats.
Go
1
star
47

r_time

C library providing the ability to get time from remote servers.
C
1
star
48

fips_dockerfiles

Dockerfile
1
star
49

pwc

Pascal
1
star
50

itsnotgolang

Go
1
star
51

micro-chat

C
1
star
52

dictu.vim

Vim Script
1
star
53

dictum

Makefile
1
star
54

Felix

Felix is an application to be run on Asterisk servers and Kamalio servers when there's an environment needing a process to register in and out carriers and Asterisk servers from the cluster.
Java
1
star