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 ¶
- Variables
- type CharSet
- type Spinner
- func (s *Spinner) HideCursor()
- func (s *Spinner) Restart()
- func (s *Spinner) SetCancelKeys(keys []keys.KeyCode)
- func (s *Spinner) SetColor(c color.Color)
- func (s *Spinner) SetFinalMsg(fm string)
- func (s *Spinner) SetPrefix(p string)
- func (s *Spinner) SetSuffix(sf string)
- func (s *Spinner) SetWriter(w io.Writer)
- func (s *Spinner) SetWriterFile(f *os.File)
- func (s *Spinner) ShowCursor()
- func (s *Spinner) Start()
- func (s *Spinner) Stop()
- type SpinnerBuilder
- func (s *SpinnerBuilder) Build() *Spinner
- func (s *SpinnerBuilder) WithCancelKeys(cancelKeys []keys.KeyCode) *SpinnerBuilder
- func (s *SpinnerBuilder) WithColor(color color.Color) *SpinnerBuilder
- func (s *SpinnerBuilder) WithFinalMsg(finalMsg string) *SpinnerBuilder
- func (s *SpinnerBuilder) WithPostUpdate(postUpdate func(s *Spinner)) *SpinnerBuilder
- func (s *SpinnerBuilder) WithPreUpdate(preUpdate func(s *Spinner)) *SpinnerBuilder
- func (s *SpinnerBuilder) WithPrefix(prefix string) *SpinnerBuilder
- func (s *SpinnerBuilder) WithSuffix(suffix string) *SpinnerBuilder
- func (s *SpinnerBuilder) WithVariant(variant SpinnerVariant) *SpinnerBuilder
- func (s *SpinnerBuilder) WithWriter(writer io.Writer) *SpinnerBuilder
- func (s *SpinnerBuilder) WithWriterFile(writerFile *os.File) *SpinnerBuilder
- type SpinnerVariant
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 Spinner ¶
type Spinner struct { Writer io.Writer WriterFile *os.File PreUpdate func(s *Spinner) PostUpdate func(s *Spinner) FinalMsg string Prefix string Suffix string CancelKeys []keys.KeyCode Color color.Color // contains filtered or unexported fields }
Spinner represents a thread-safe spinner (s *Spinner) Set customizable s such as character sets, prefix, suffix, and color.
func (*Spinner) Restart ¶
func (s *Spinner) Restart()
Restart stops the spinner and starts it again.
func (*Spinner) SetCancelKeys ¶
SetCancelKeys returns an function that sets the cancelation keys for the Spinner.
func (*Spinner) SetFinalMsg ¶
SetFinalMsg returns an function that sets the final message of a Spinner.
func (*Spinner) SetWriterFile ¶
SetWriterFile adds the given writer to the spinner.
type SpinnerBuilder ¶
type SpinnerBuilder struct {
// contains filtered or unexported fields
}
SpinnerBuilder is a builder for the spinner.
func (*SpinnerBuilder) Build ¶
func (s *SpinnerBuilder) Build() *Spinner
Build builds a new spinner with the given options.
func (*SpinnerBuilder) WithCancelKeys ¶
func (s *SpinnerBuilder) WithCancelKeys(cancelKeys []keys.KeyCode) *SpinnerBuilder
WithCancelKeys sets the keys that can cancel the spinner.
func (*SpinnerBuilder) WithColor ¶
func (s *SpinnerBuilder) WithColor(color color.Color) *SpinnerBuilder
WithColor sets the color of the spinner.
func (*SpinnerBuilder) WithFinalMsg ¶
func (s *SpinnerBuilder) WithFinalMsg(finalMsg string) *SpinnerBuilder
WithFinalMsg sets the final message of the spinner.
func (*SpinnerBuilder) WithPostUpdate ¶
func (s *SpinnerBuilder) WithPostUpdate(postUpdate func(s *Spinner)) *SpinnerBuilder
WithPostUpdate sets the post update function of the spinner.
func (*SpinnerBuilder) WithPreUpdate ¶
func (s *SpinnerBuilder) WithPreUpdate(preUpdate func(s *Spinner)) *SpinnerBuilder
WithPreUpdate sets the pre update function of the spinner.
func (*SpinnerBuilder) WithPrefix ¶
func (s *SpinnerBuilder) WithPrefix(prefix string) *SpinnerBuilder
WithPrefix sets the prefix of the spinner.
func (*SpinnerBuilder) WithSuffix ¶
func (s *SpinnerBuilder) WithSuffix(suffix string) *SpinnerBuilder
WithSuffix sets the suffix of the spinner.
func (*SpinnerBuilder) WithVariant ¶
func (s *SpinnerBuilder) WithVariant(variant SpinnerVariant) *SpinnerBuilder
WithVariant sets the variant of the spinner.
func (*SpinnerBuilder) WithWriter ¶
func (s *SpinnerBuilder) WithWriter(writer io.Writer) *SpinnerBuilder
WithWriter sets the writer of the spinner.
func (*SpinnerBuilder) WithWriterFile ¶
func (s *SpinnerBuilder) WithWriterFile(writerFile *os.File) *SpinnerBuilder
WithWriterFile sets the writer file of the spinner.
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.