spinner

package
v0.4.0-beta.47 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	TICK  = "✔"
	CROSS = "✖"
	SKIP  = "⋯"
	DASH  = "-"
)

Variables

View Source
var CharSets = map[int][]string{
	0:  {"←", "↖", "↑", "↗", "→", "↘", "↓", "↙"},
	1:  {"▁", "▃", "▄", "▅", "▆", "▇", "█", "▇", "▆", "▅", "▄", "▃", "▁"},
	2:  {"▖", "▘", "▝", "▗"},
	3:  {"┤", "┘", "┴", "└", "├", "┌", "┬", "┐"},
	4:  {"◢", "◣", "◤", "◥"},
	5:  {"◰", "◳", "◲", "◱"},
	6:  {"◴", "◷", "◶", "◵"},
	7:  {"◐", "◓", "◑", "◒"},
	8:  {".", "o", "O", "@", "*"},
	9:  {"|", "/", "-", "\\"},
	10: {"◡◡", "⊙⊙", "◠◠"},
	11: {"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"},
	12: {">))'>", " >))'>", "  >))'>", "   >))'>", "    >))'>", "   <'((<", "  <'((<", " <'((<"},
	13: {"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"},
	14: {"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"},
	15: {"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"},
	16: {"▉", "▊", "▋", "▌", "▍", "▎", "▏", "▎", "▍", "▌", "▋", "▊", "▉"},
	17: {"■", "□", "▪", "▫"},
	18: {"←", "↑", "→", "↓"},
	19: {"╫", "╪"},
	20: {"⇐", "⇖", "⇑", "⇗", "⇒", "⇘", "⇓", "⇙"},
	21: {"⠁", "⠁", "⠉", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠤", "⠄", "⠄", "⠤", "⠠", "⠠", "⠤", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋", "⠉", "⠈", "⠈"},
	22: {"⠈", "⠉", "⠋", "⠓", "⠒", "⠐", "⠐", "⠒", "⠖", "⠦", "⠤", "⠠", "⠠", "⠤", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋", "⠉", "⠈"},
	23: {"⠁", "⠉", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠤", "⠄", "⠄", "⠤", "⠴", "⠲", "⠒", "⠂", "⠂", "⠒", "⠚", "⠙", "⠉", "⠁"},
	24: {"⠋", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋"},
	25: {"ヲ", "ァ", "ィ", "ゥ", "ェ", "ォ", "ャ", "ュ", "ョ", "ッ", "ア", "イ", "ウ", "エ", "オ", "カ", "キ", "ク", "ケ", "コ", "サ", "シ", "ス", "セ", "ソ", "タ", "チ", "ツ", "テ", "ト", "ナ", "ニ", "ヌ", "ネ", "ノ", "ハ", "ヒ", "フ", "ヘ", "ホ", "マ", "ミ", "ム", "メ", "モ", "ヤ", "ユ", "ヨ", "ラ", "リ", "ル", "レ", "ロ", "ワ", "ン"},
	26: {".", "..", "..."},
	27: {"▁", "▂", "▃", "▄", "▅", "▆", "▇", "█", "▉", "▊", "▋", "▌", "▍", "▎", "▏", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█", "▇", "▆", "▅", "▄", "▃", "▂", "▁"},
	28: {".", "o", "O", "°", "O", "o", "."},
	29: {"+", "x"},
	30: {"v", "<", "^", ">"},
	31: {">>--->", " >>--->", "  >>--->", "   >>--->", "    >>--->", "    <---<<", "   <---<<", "  <---<<", " <---<<", "<---<<"},
	32: {"|", "||", "|||", "||||", "|||||", "|||||||", "||||||||", "|||||||", "||||||", "|||||", "||||", "|||", "||", "|"},
	33: {"[          ]", "[=         ]", "[==        ]", "[===       ]", "[====      ]", "[=====     ]", "[======    ]", "[=======   ]", "[========  ]", "[========= ]", "[==========]"},
	34: {"(*---------)", "(-*--------)", "(--*-------)", "(---*------)", "(----*-----)", "(-----*----)", "(------*---)", "(-------*--)", "(--------*-)", "(---------*)"},
	35: {"█▒▒▒▒▒▒▒▒▒", "███▒▒▒▒▒▒▒", "█████▒▒▒▒▒", "███████▒▒▒", "██████████"},
	36: {"[                    ]", "[=>                  ]", "[===>                ]", "[=====>              ]", "[======>             ]", "[========>           ]", "[==========>         ]", "[============>       ]", "[==============>     ]", "[================>   ]", "[==================> ]", "[===================>]"},
	39: {"🌍", "🌎", "🌏"},
	40: {"◜", "◝", "◞", "◟"},
	41: {"⬒", "⬔", "⬓", "⬕"},
	42: {"⬖", "⬘", "⬗", "⬙"},
	43: {"[>>>          >]", "[]>>>>        []", "[]  >>>>      []", "[]    >>>>    []", "[]      >>>>  []", "[]        >>>>[]", "[>>          >>]"},
	44: {"♠", "♣", "♥", "♦"},
	45: {"➞", "➟", "➠", "➡", "➠", "➟"},
	46: {"  |  ", ` \   `, "_    ", ` \   `, "  |  ", "   / ", "    _", "   / "},
	47: {"  . . . .", ".   . . .", ". .   . .", ". . .   .", ". . . .  ", ". . . . ."},
	48: {" |     ", "  /    ", "   _   ", `    \  `, "     | ", `    \  `, "   _   ", "  /    "},
	49: {"⎺", "⎻", "⎼", "⎽", "⎼", "⎻"},
	50: {"▹▹▹▹▹", "▸▹▹▹▹", "▹▸▹▹▹", "▹▹▸▹▹", "▹▹▹▸▹", "▹▹▹▹▸"},
	51: {"[    ]", "[   =]", "[  ==]", "[ ===]", "[====]", "[=== ]", "[==  ]", "[=   ]"},
	52: {"( ●    )", "(  ●   )", "(   ●  )", "(    ● )", "(     ●)", "(    ● )", "(   ●  )", "(  ●   )", "( ●    )"},
	53: {"✶", "✸", "✹", "✺", "✹", "✷"},
	54: {"▐|\\____________▌", "▐_|\\___________▌", "▐__|\\__________▌", "▐___|\\_________▌", "▐____|\\________▌", "▐_____|\\_______▌", "▐______|\\______▌", "▐_______|\\_____▌", "▐________|\\____▌", "▐_________|\\___▌", "▐__________|\\__▌", "▐___________|\\_▌", "▐____________|\\▌", "▐____________/|▌", "▐___________/|_▌", "▐__________/|__▌", "▐_________/|___▌", "▐________/|____▌", "▐_______/|_____▌", "▐______/|______▌", "▐_____/|_______▌", "▐____/|________▌", "▐___/|_________▌", "▐__/|__________▌", "▐_/|___________▌", "▐/|____________▌"},
	55: {"▐⠂       ▌", "▐⠈       ▌", "▐ ⠂      ▌", "▐ ⠠      ▌", "▐  ⡀     ▌", "▐  ⠠     ▌", "▐   ⠂    ▌", "▐   ⠈    ▌", "▐    ⠂   ▌", "▐    ⠠   ▌", "▐     ⡀  ▌", "▐     ⠠  ▌", "▐      ⠂ ▌", "▐      ⠈ ▌", "▐       ⠂▌", "▐       ⠠▌", "▐       ⡀▌", "▐      ⠠ ▌", "▐      ⠂ ▌", "▐     ⠈  ▌", "▐     ⠂  ▌", "▐    ⠠   ▌", "▐    ⡀   ▌", "▐   ⠠    ▌", "▐   ⠂    ▌", "▐  ⠈     ▌", "▐  ⠂     ▌", "▐ ⠠      ▌", "▐ ⡀      ▌", "▐⠠       ▌"},
	56: {"¿", "?"},
	57: {"⢹", "⢺", "⢼", "⣸", "⣇", "⡧", "⡗", "⡏"},
	58: {"⢄", "⢂", "⢁", "⡁", "⡈", "⡐", "⡠"},
	59: {".  ", ".. ", "...", " ..", "  .", "   "},
	60: {".", "o", "O", "°", "O", "o", "."},
	61: {"▓", "▒", "░"},
	62: {"▌", "▀", "▐", "▄"},
	63: {"⊶", "⊷"},
	64: {"▪", "▫"},
	65: {"□", "■"},
	66: {"▮", "▯"},
	67: {"-", "=", "≡"},
	68: {"d", "q", "p", "b"},
	69: {"∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙"},
	70: {"🌑 ", "🌒 ", "🌓 ", "🌔 ", "🌕 ", "🌖 ", "🌗 ", "🌘 "},
	71: {"☗", "☖"},
	72: {"⧇", "⧆"},
	73: {"◉", "◎"},
	74: {"㊂", "㊀", "㊁"},
	75: {"⦾", "⦿"},
	76: {"ဝ", "၀"},
	77: {"▌", "▀", "▐▄"},
}

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 ActualSpinner

type ActualSpinner struct {
	Delay time.Duration // Delay is the speed of the indicator

	Prefix   string // Prefix is the text preppended to the indicator
	Suffix   string // Suffix is the text appended to the indicator
	FinalMSG string // string displayed after Stop() is called

	Writer io.Writer // to make testing better, exported so users have access. Use `WithWriter` to update after initialization.

	HideCursor bool                   // hideCursor determines if the cursor is visible
	PreUpdate  func(s *ActualSpinner) // will be triggered before every spinner update
	PostUpdate func(s *ActualSpinner) // will be triggered after every spinner update
	// contains filtered or unexported fields
}

ActualSpinner struct to hold the provided options.

func NewActualSpinner

func NewActualSpinner(cs []string, d time.Duration, options ...Option) *ActualSpinner

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

func (*ActualSpinner) Active

func (s *ActualSpinner) Active() bool

Active will return whether or not the spinner is currently active.

func (*ActualSpinner) Color

func (s *ActualSpinner) Color(colors ...string) error

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

func (*ActualSpinner) HideAndExecute

func (s *ActualSpinner) HideAndExecute(f func())

func (*ActualSpinner) Lock

func (s *ActualSpinner) Lock()

Lock allows for manual control to lock the spinner.

func (*ActualSpinner) Pause

func (s *ActualSpinner) Pause()

func (*ActualSpinner) Repaint

func (s *ActualSpinner) Repaint()

func (*ActualSpinner) Restart

func (s *ActualSpinner) Restart()

Restart will stop and start the indicator.

func (*ActualSpinner) Reverse

func (s *ActualSpinner) Reverse()

Reverse will reverse the order of the slice assigned to the indicator.

func (*ActualSpinner) Start

func (s *ActualSpinner) Start()

Start will start the indicator.

func (*ActualSpinner) Stop

func (s *ActualSpinner) Stop()

Stop stops the indicator.

func (*ActualSpinner) Unlock

func (s *ActualSpinner) Unlock()

Unlock allows for manual control to unlock the spinner.

func (*ActualSpinner) UpdateCharSet

func (s *ActualSpinner) UpdateCharSet(cs []string)

UpdateCharSet will change the current character set to the given one.

func (*ActualSpinner) UpdateSpeed

func (s *ActualSpinner) UpdateSpeed(d time.Duration)

UpdateSpeed will set the indicator delay to the given value.

type CISpinner

type CISpinner struct {
	// contains filtered or unexported fields
}

func NewCISpinner

func NewCISpinner(out io.Writer, colors aurora.Aurora) *CISpinner

func (*CISpinner) Active

func (s *CISpinner) Active() bool

func (*CISpinner) CurrentHeading

func (s *CISpinner) CurrentHeading() string

func (*CISpinner) Error

func (s *CISpinner) Error(message string)

func (*CISpinner) HideAndExecute

func (s *CISpinner) HideAndExecute(f func())

func (*CISpinner) NewStep

func (s *CISpinner) NewStep(message string)

func (*CISpinner) SetMessage

func (s *CISpinner) SetMessage(message string)

func (*CISpinner) Skip

func (s *CISpinner) Skip()

func (*CISpinner) StampShadow

func (s *CISpinner) StampShadow()

func (*CISpinner) Start

func (s *CISpinner) Start()

func (*CISpinner) Stop

func (s *CISpinner) Stop()

func (*CISpinner) Success

func (s *CISpinner) Success(message string)

type GitlabSpinner

type GitlabSpinner struct {
	// contains filtered or unexported fields
}

func NewGitlabSpinner

func NewGitlabSpinner(out io.Writer, colors aurora.Aurora) *GitlabSpinner

func (*GitlabSpinner) Active

func (s *GitlabSpinner) Active() bool

func (*GitlabSpinner) CurrentHeading

func (s *GitlabSpinner) CurrentHeading() string

func (*GitlabSpinner) Error

func (s *GitlabSpinner) Error(message string)

func (*GitlabSpinner) HideAndExecute

func (s *GitlabSpinner) HideAndExecute(f func())

func (*GitlabSpinner) NewStep

func (s *GitlabSpinner) NewStep(message string)

func (*GitlabSpinner) SetMessage

func (s *GitlabSpinner) SetMessage(message string)

func (*GitlabSpinner) Skip

func (s *GitlabSpinner) Skip()

func (*GitlabSpinner) StampShadow

func (s *GitlabSpinner) StampShadow()

func (*GitlabSpinner) Start

func (s *GitlabSpinner) Start()

func (*GitlabSpinner) Stop

func (s *GitlabSpinner) Stop()

func (*GitlabSpinner) Success

func (s *GitlabSpinner) Success(message string)

type NullSpinner

type NullSpinner struct {
	// contains filtered or unexported fields
}

func NewNullSpinner

func NewNullSpinner() *NullSpinner

func (*NullSpinner) Active

func (s *NullSpinner) Active() bool

func (*NullSpinner) CurrentHeading

func (s *NullSpinner) CurrentHeading() string

func (*NullSpinner) Error

func (s *NullSpinner) Error(message string)

func (*NullSpinner) HideAndExecute

func (s *NullSpinner) HideAndExecute(f func())

func (*NullSpinner) NewStep

func (s *NullSpinner) NewStep(message string)

func (*NullSpinner) SetMessage

func (s *NullSpinner) SetMessage(message string)

func (*NullSpinner) Skip

func (s *NullSpinner) Skip()

func (*NullSpinner) StampShadow

func (s *NullSpinner) StampShadow()

func (*NullSpinner) Start

func (s *NullSpinner) Start()

func (*NullSpinner) Stop

func (s *NullSpinner) Stop()

func (*NullSpinner) Success

func (s *NullSpinner) Success(message string)

type Option

type Option func(*ActualSpinner)

Option is a function that takes a spinner and applies a given configuration.

func WithColor

func WithColor(color string) Option

WithColor adds the given color to the spinner.

func WithFinalMSG

func WithFinalMSG(finalMsg string) Option

WithFinalMSG adds the given string ot the spinner as the final message to be written.

func WithHiddenCursor

func WithHiddenCursor(hideCursor bool) Option

WithHiddenCursor hides the cursor if hideCursor = true given.

func WithSuffix

func WithSuffix(suffix string) Option

WithSuffix adds the given string to the spinner as the suffix.

func WithWriter

func WithWriter(w io.Writer) Option

WithWriter adds the given writer to the spinner. This function should be favored over directly assigning to the struct value.

type Options

type Options struct {
	Color      string
	Suffix     string
	FinalMSG   string
	HideCursor bool
}

Options contains fields to configure the spinner.

type StdoutSpinner

type StdoutSpinner struct {
	// contains filtered or unexported fields
}

func NewStdoutSpinner

func NewStdoutSpinner(colorMode aurora.Aurora, colorsEnabled bool, out io.Writer) *StdoutSpinner

func (*StdoutSpinner) Active

func (s *StdoutSpinner) Active() bool

func (*StdoutSpinner) CurrentHeading

func (s *StdoutSpinner) CurrentHeading() string

func (*StdoutSpinner) Error

func (s *StdoutSpinner) Error(message string)

func (*StdoutSpinner) HideAndExecute

func (s *StdoutSpinner) HideAndExecute(f func())

func (*StdoutSpinner) NewStep

func (s *StdoutSpinner) NewStep(message string)

func (*StdoutSpinner) SetMessage

func (s *StdoutSpinner) SetMessage(message string)

func (*StdoutSpinner) Skip

func (s *StdoutSpinner) Skip()

func (*StdoutSpinner) Spin

func (s *StdoutSpinner) Spin()

func (*StdoutSpinner) StampShadow

func (s *StdoutSpinner) StampShadow()

func (*StdoutSpinner) Start

func (s *StdoutSpinner) Start()

func (*StdoutSpinner) Stop

func (s *StdoutSpinner) Stop()

func (*StdoutSpinner) Success

func (s *StdoutSpinner) Success(message string)

type SubenvSpinner

type SubenvSpinner struct {
	// contains filtered or unexported fields
}

func NewSubenvSpinner

func NewSubenvSpinner(env map[string]string, spinner wrappableSpinner) *SubenvSpinner

func (*SubenvSpinner) Active

func (s *SubenvSpinner) Active() bool

func (*SubenvSpinner) CurrentHeading

func (s *SubenvSpinner) CurrentHeading() string

func (*SubenvSpinner) Error

func (s *SubenvSpinner) Error(message string)

func (*SubenvSpinner) HideAndExecute

func (s *SubenvSpinner) HideAndExecute(f func())

func (*SubenvSpinner) NewStep

func (s *SubenvSpinner) NewStep(message string)

func (*SubenvSpinner) SetMessage

func (s *SubenvSpinner) SetMessage(message string)

func (*SubenvSpinner) Skip

func (s *SubenvSpinner) Skip()

func (*SubenvSpinner) StampShadow

func (s *SubenvSpinner) StampShadow()

func (*SubenvSpinner) Start

func (s *SubenvSpinner) Start()

func (*SubenvSpinner) Stop

func (s *SubenvSpinner) Stop()

func (*SubenvSpinner) SubEnv

func (s *SubenvSpinner) SubEnv(message string) string

func (*SubenvSpinner) Success

func (s *SubenvSpinner) Success(message string)

Jump to

Keyboard shortcuts

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