Documentation ¶
Overview ¶
Package spin provides a thread safe Spinner with various available character sets, prefix, suffix and color. The Spinner can be controlled using an Options pattern. Example:
s := spin.New(spin.BouncingBar, time.Millisecond * 10, spin.WithPrefix("SPINNING "), spin.WithSuffix("AFTER"), spin.WithColor(color.FgGreen), spin.WithFinalMsg("BYE!")) s.Start() time.Sleep(time.Second * 3) s.Stop()
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // GrowVertical is a spinner variant that grows the spinner vertically. GrowVertical = NewSpinnerVariant(CharSets[0], 80) // Bounce is a spinner variant that bounces the spinner. Bounce = NewSpinnerVariant(CharSets[1], 120) // Dots1 is a spinner variant that shows three dots. Dots1 = NewSpinnerVariant(CharSets[2], 80) // Dots2 is a spinner variant that shows three dots. Dots2 = NewSpinnerVariant(CharSets[3], 80) // Dots3 is a spinner variant that shows three dots. Dots3 = NewSpinnerVariant(CharSets[4], 80) // Letters is a spinner variant that shows the letters a-z. Letters = NewSpinnerVariant(CharSets[5], 120) // GrowHorizontal is a spinner variant that grows the spinner horizontally. GrowHorizontal = NewSpinnerVariant(CharSets[6], 80) // Simple is a spinner variant that shows a simple spinner. Simple = NewSpinnerVariant(CharSets[7], 120) // GrowHV is a spinner variant that grows the spinner horizontally and vertically. GrowHV = NewSpinnerVariant(CharSets[8], 80) // Arc is a spinner variant that shows an arc. Arc = NewSpinnerVariant(CharSets[9], 80) // BouncingBar is a spinner variant that shows a bouncing bar. BouncingBar = NewSpinnerVariant(CharSets[10], 80) // BouncingSimple is a spinner variant that shows a bouncing simple spinner. BouncingSimple = NewSpinnerVariant(CharSets[11], 80) // MovingDots is a spinner variant that shows moving dots. MovingDots = NewSpinnerVariant(CharSets[12], 80) )
var CharSets = map[int][]string{
0: {"▁", "▃", "▄", "▅", "▆", "▇", "█", "▇", "▆", "▅", "▄", "▃", "▁"},
1: {"▖", "▘", "▝", "▗"},
2: {"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"},
3: {"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"},
4: {"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"},
5: {"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"},
6: {"▉", "▊", "▋", "▌", "▍", "▎", "▏", "▎", "▍", "▌", "▋", "▊", "▉"},
7: {". ", ".. ", "..."},
8: {"▁", "▂", "▃", "▄", "▅", "▆", "▇", "█", "▉", "▊", "▋", "▌", "▍", "▎", "▏", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█", "▇", "▆", "▅", "▄", "▃", "▂", "▁"},
9: {"◜", "◝", "◞", "◟"},
10: {"(● )", "( ● )", "( ● )", "( ● )", "( ● )", "( ●)", "( ● )", "( ● )", "( ● )", "( ● )"},
11: {". ", ".. ", "...", " ..", " .", " "},
12: {"∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙"},
}
CharSets contains the available character sets
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(s *Spinner)
Option is a function that modifies a Spinner.
func WithCancelKeys ¶
WithCancelKeys returns an Option function that sets the cancelation keys for the Spinner.
func WithFinalMsg ¶
WithFinalMsg returns an Option function that sets the final message of a Spinner.
func WithPrefix ¶
WithPrefix returns an Option function that sets the Prefix field of a Spinner.
func WithSuffix ¶
WithSuffix returns an Option function that sets the suffix of a Spinner.
func WithWriter ¶
WithWriter takes an io.Writer and sets the spinner output.
func WithWriterFile ¶
WithWriterFile adds the given writer to the spinner.
type Spinner ¶
type Spinner struct { CancelKeys []keys.KeyCode Writer io.Writer WriterFile *os.File Color color.Color FinalMsg string Prefix string Suffix string PreUpdate func(s *Spinner) PostUpdate func(s *Spinner) // contains filtered or unexported fields }
Spinner represents a thread-safe spinner with customizable options such as character sets, prefix, suffix, and color.
func New ¶
func New(variant SpinnerVariant, options ...Option) *Spinner
New creates a new Spinner with the provided CharSet, delay, and options.
type SpinnerVariant ¶
type SpinnerVariant struct { Interval int // contains filtered or unexported fields }
SpinnerVariant represents a variant of a spinner with a specific character set and interval.
func NewSpinnerVariant ¶
func NewSpinnerVariant(charSet CharSet, interval int) SpinnerVariant
NewSpinnerVariant creates a new SpinnerVariant with the given character set and interval.