spinner

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2023 License: MIT Imports: 3 Imported by: 1

README

spinner

Spinner allows creating simple or complex spinners. See godocs for more.

Documentation

Overview

Package spinner allows creating and using spinners that indicate that a process is working in the background.

Example

This function pretty much shows all you need for using a spinner:

  1. create a spinner
  2. set a style
  3. use .Next()
var s Spinner
s.SetStyle("dots")

for i := 0; i < 100; i++ {
	fmt.Printf("\rworking%v", s.Next())
	time.Sleep(80 * time.Millisecond)
}
Output:

Example (MultipleSpinner)

This shows how to use multiple different spinners at once.

var s1, s2, s3 Spinner
// note that s1 has not been assigned a style, therefore the default style
// is used
s2.SetStyle("windows-10")
s3.SetStyle("clock")

for i := 0; i < 100; i++ {
	fmt.Printf(" %v\tloading protocols\n %v\tbooting bloated OS\n %v\tperforming checks\r\033[F\033[F", s1.Next(), s2.Next(), s3.Next())
	time.Sleep(80 * time.Millisecond)
}

fmt.Printf(" %v\n %v\n %v\n", s1.Clear(), s2.Clear(), s3.Clear())
Output:

Example (Multiuse)

This shows the same spinner 3 times and cleans up afterwards

var s1 Spinner
s1.SetStyle("bouncing-bar")

for i := 0; i < 100; i++ {
	fmt.Printf(" %v\tdo stuff\n %v\texecuting something else\n %v\twaiting for some seconds\r\033[F\033[F", s1.Next(), s1.Current(), s1.Current())
	time.Sleep(80 * time.Millisecond)
}

// removes the spinner-characters but leaves the text untouched
fmt.Printf(" %v\n %v\n %v\n", s1.Clear(), s1.Clear(), s1.Clear())
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var SpinnerStyles = map[string][]string{
	"arrow":             {"←", "↖", "↑", "↗", "→", "↘", "↓", "↙"},
	"blinker":           {"⊶", "⊷"},
	"bouncing-ball":     {"( ●    )", "(  ●   )", "(   ●  )", "(    ● )", "(     ●)", "(    ● )", "(   ●  )", "(  ●   )", "( ●    )", "(●     )"},
	"bouncing-bar":      {"[    ]", "[=   ]", "[==  ]", "[=== ]", "[ ===]", "[  ==]", "[   =]", "[    ]", "[   =]", "[  ==]", "[ ===]", "[====]", "[=== ]", "[==  ]", "[=   ]"},
	"braille":           {"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"},
	"braille-thin":      {"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"},
	"circle":            {"◜", "◠", "◝", "◞", "◡", "◟"},
	"clock":             {"🕛 ", "🕐 ", "🕑 ", "🕒 ", "🕓 ", "🕔 ", "🕕 ", "🕖 ", "🕗 ", "🕘 ", "🕙 ", "🕚 "},
	"do-a-flip":         {"_", "_", "_", "-", "`", "`", "'", "´", "-", "_", "_", "_"},
	"dots":              {".  ", ".. ", "..."},
	"dots-bounce":       {".  ", ".. ", "...", " ..", "  .", " ..", "...", ".. "},
	"expand-block":      {"▏", "▎", "▍", "▌", "▋", "▊", "▉", "▊", "▋", "▌", "▍", "▎"},
	"grow-block":        {"▁", "▃", "▄", "▅", "▆", "▇", "▆", "▅", "▄", "▃"},
	"half-circle":       {"◐", "◓", "◑", "◒"},
	"line":              {"|", "/", "-", "\\"},
	"noise":             {"▓", "▒", "░"},
	"pipe":              {"┤", "┘", "┴", "└", "├", "┌", "┬", "┐"},
	"pointer-flow":      {"▹▹▹▹▹", "▸▹▹▹▹", "▹▸▹▹▹", "▹▹▸▹▹", "▹▹▹▸▹", "▹▹▹▹▸"},
	"rotation-box":      {"▌", "▀", "▐", "▄"},
	"rotation-box-tiny": {"▖", "▘", "▝", "▗"},
	"shape1":            {"🔸", "🔶", "🟠", "🔶"},
	"triangle":          {"◢", "◣", "◤", "◥"},
	"windows-10":        {"⢀⠀", "⡀⠀", "⠄⠀", "⢂⠀", "⡂⠀", "⠅⠀", "⢃⠀", "⡃⠀", "⠍⠀", "⢋⠀", "⡋⠀", "⠍⠁", "⢋⠁", "⡋⠁", "⠍⠉", "⠋⠉", "⠋⠉", "⠉⠙", "⠉⠙", "⠉⠩", "⠈⢙", "⠈⡙", "⢈⠩", "⡀⢙", "⠄⡙", "⢂⠩", "⡂⢘", "⠅⡘", "⢃⠨", "⡃⢐", "⠍⡐", "⢋⠠", "⡋⢀", "⠍⡁", "⢋⠁", "⡋⠁", "⠍⠉", "⠋⠉", "⠋⠉", "⠉⠙", "⠉⠙", "⠉⠩", "⠈⢙", "⠈⡙", "⠈⠩", "⠀⢙", "⠀⡙", "⠀⠩", "⠀⢘", "⠀⡘", "⠀⠨", "⠀⢐", "⠀⡐", "⠀⠠", "⠀⢀", "⠀⡀"},
	"":                  {"|", "/", "-", "\\"},
}

SpinnerStyles contains the styles of spinners

Functions

func DefineStyle

func DefineStyle(name string, characters []string)

DefineStyle allows registering a custom spinner-style to use. If the name is already defined it is overwritten. Directly defining them is possible but not recommended.

Types

type Spinner

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

Spinner contains the settings of a spinner

func (*Spinner) Clear

func (s *Spinner) Clear() string

Clear returns the amount of characters for the first spinner-state in spaces in order to clear the spinner if required.

func (*Spinner) Current

func (s *Spinner) Current() string

Current returns the current character for the spinner

func (*Spinner) Next

func (s *Spinner) Next() string

Next returns the next character for the spinner

func (*Spinner) SetStyle

func (s *Spinner) SetStyle(style string)

SetStyle loads a style into the spinner

Jump to

Keyboard shortcuts

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