spinner

package
v0.0.0-...-a03e72d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2015 License: Apache-2.0, Apache-2.0 Imports: 8 Imported by: 0

README

Spinner

GoDoc Build Status

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

(Numbered by their slice index)

    1. ←↖↑↗→↘↓↙
    1. ▁▃▄▅▆▇█▇▆▅▄▃▁
    1. ▖▘▝▗
    1. ┤┘┴└├┌┬┐
    1. ◢◣◤◥
    1. ◰◳◲◱
    1. ◴◷◶◵
    1. ◐◓◑◒
    1. .oO@*
    1. |/-\
    1. ◡◡⊙⊙◠◠
    1. ⣾⣽⣻⢿⡿⣟⣯⣷
    1. >))'> >))'> >))'> >))'> >))'> <'((< <'((< <'((<
    1. ⠁⠂⠄⡀⢀⠠⠐⠈
    1. ⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏
    1. abcdefghijklmnopqrstuvwxyz
    1. ▉▊▋▌▍▎▏▎▍▌▋▊▉
    1. ■□▪▫
    1. ←↑→↓
    1. ╫╪
    1. ⇐⇖⇑⇗⇒⇘⇓⇙
    1. ⠁⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈⠈
    1. ⠈⠉⠋⠓⠒⠐⠐⠒⠖⠦⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈
    1. ⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠴⠲⠒⠂⠂⠒⠚⠙⠉⠁
    1. ⠋⠙⠚⠒⠂⠂⠒⠲⠴⠦⠖⠒⠐⠐⠒⠓⠋
    1. ヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン
    1. . .. ...
    1. ▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▏▎▍▌▋▊▉█▇▆▅▄▃▂▁
    1. .oO°Oo.
    1. +x
    1. v<^>
    1. >>---> >>---> >>---> >>---> >>---> <---<< <---<< <---<< <---<< <---<<
    1. | || ||| |||| ||||| |||||| ||||| |||| ||| || |
    1. [] [=] [==] [===] [====] [=====] [======] [=======] [========] [=========] [==========]
    1. (*---------) (-*--------) (--*-------) (---*------) (----*-----) (-----*----) (------*---) (-------*--) (--------*-) (---------*)
    1. █▒▒▒▒▒▒▒▒▒ ███▒▒▒▒▒▒▒ █████▒▒▒▒▒ ███████▒▒▒ ██████████

Features

  • Start
  • Stop
  • Restart
  • Reverse direction
  • Update the spinner character set
  • Update the spinner speed
  • Prefix or append text
  • Change spinner color
  • Get spinner status

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. This will restart the spinner with the new color.

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

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.ST)

Documentation

Overview

Package spinner is a simple package to add a spinner/progress indicator to your application.

Index

Constants

This section is empty.

Variables

View Source
var CharSets = [][]string{
	{"←", "↖", "↑", "↗", "→", "↘", "↓", "↙"},
	{"▁", "▃", "▄", "▅", "▆", "▇", "█", "▇", "▆", "▅", "▄", "▃", "▁"},
	{"▖", "▘", "▝", "▗"},
	{"┤", "┘", "┴", "└", "├", "┌", "┬", "┐"},
	{"◢", "◣", "◤", "◥"},
	{"◰", "◳", "◲", "◱"},
	{"◴", "◷", "◶", "◵"},
	{"◐", "◓", "◑", "◒"},
	{".", "o", "O", "@", "*"},
	{"|", "/", "-", "\\"},
	{"◡◡", "⊙⊙", "◠◠"},
	{"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"},
	{">))'>", " >))'>", "  >))'>", "   >))'>", "    >))'>", "   <'((<", "  <'((<", " <'((<"},
	{"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"},
	{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"},
	{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"},
	{"▉", "▊", "▋", "▌", "▍", "▎", "▏", "▎", "▍", "▌", "▋", "▊", "▉"},
	{"■", "□", "▪", "▫"},
	{"←", "↑", "→", "↓"},
	{"╫", "╪"},
	{"⇐", "⇖", "⇑", "⇗", "⇒", "⇘", "⇓", "⇙"},
	{"⠁", "⠁", "⠉", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠤", "⠄", "⠄", "⠤", "⠠", "⠠", "⠤", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋", "⠉", "⠈", "⠈"},
	{"⠈", "⠉", "⠋", "⠓", "⠒", "⠐", "⠐", "⠒", "⠖", "⠦", "⠤", "⠠", "⠠", "⠤", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋", "⠉", "⠈"},
	{"⠁", "⠉", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠤", "⠄", "⠄", "⠤", "⠴", "⠲", "⠒", "⠂", "⠂", "⠒", "⠚", "⠙", "⠉", "⠁"},
	{"⠋", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋"},
	{"ヲ", "ァ", "ィ", "ゥ", "ェ", "ォ", "ャ", "ュ", "ョ", "ッ", "ア", "イ", "ウ", "エ", "オ", "カ", "キ", "ク", "ケ", "コ", "サ", "シ", "ス", "セ", "ソ", "タ", "チ", "ツ", "テ", "ト", "ナ", "ニ", "ヌ", "ネ", "ノ", "ハ", "ヒ", "フ", "ヘ", "ホ", "マ", "ミ", "ム", "メ", "モ", "ヤ", "ユ", "ヨ", "ラ", "リ", "ル", "レ", "ロ", "ワ", "ン"},
	{".", "..", "..."},
	{"▁", "▂", "▃", "▄", "▅", "▆", "▇", "█", "▉", "▊", "▋", "▌", "▍", "▎", "▏", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█", "▇", "▆", "▅", "▄", "▃", "▂", "▁"},
	{".", "o", "O", "°", "O", "o", "."},
	{"+", "x"},
	{"v", "<", "^", ">"},
	{">>--->", " >>--->", "  >>--->", "   >>--->", "    >>--->", "    <---<<", "   <---<<", "  <---<<", " <---<<", "<---<<"},
	{"|", "||", "|||", "||||", "|||||", "|||||||", "||||||||", "|||||||", "||||||", "|||||", "||||", "|||", "||", "|"},
	{"[          ]", "[=         ]", "[==        ]", "[===       ]", "[====      ]", "[=====     ]", "[======    ]", "[=======   ]", "[========  ]", "[========= ]", "[==========]"},
	{"(*---------)", "(-*--------)", "(--*-------)", "(---*------)", "(----*-----)", "(-----*----)", "(------*---)", "(-------*--)", "(--------*-)", "(---------*)"},
	{"█▒▒▒▒▒▒▒▒▒", "███▒▒▒▒▒▒▒", "█████▒▒▒▒▒", "███████▒▒▒", "██████████"},
}

CharSets contains the available character sets

Functions

func GenerateNumberSequence

func GenerateNumberSequence(length int) []string

GenerateNumberSequence will generate a slice of integers at the provided length and convert them each to a string

Types

type Spinner

type Spinner struct {
	Delay  time.Duration // speed of the spinner
	Prefix string        // Text preppended to the spinner
	Suffix string        // Text appended to the spinner

	ST state // spinner status
	// contains filtered or unexported fields
}

Spinner struct to hold the provided options

func New

func New(c []string, t time.Duration) *Spinner

New provides a pointer to an instance of Spinner with the supplied options

func (*Spinner) Color

func (s *Spinner) Color(c string) error

Color will set the struct field for the given color to be used

func (*Spinner) Restart

func (s *Spinner) Restart()

Restart will stop and start the spinner

func (*Spinner) Reverse

func (s *Spinner) Reverse()

Reverse will reverse the order of the slice assigned to that spinner

func (*Spinner) Start

func (s *Spinner) Start()

Start will start the spinner

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner

func (*Spinner) UpdateCharSet

func (s *Spinner) UpdateCharSet(chars []string)

UpdateCharSet will change the previously select character set to the provided one

func (*Spinner) UpdateSpeed

func (s *Spinner) UpdateSpeed(delay time.Duration)

UpdateSpeed is a convenience function to not have to make you create a new instance of the Spinner

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL