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:
- create a spinner
- set a style
- 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 ¶
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 ¶
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 ¶
Clear returns the amount of characters for the first spinner-state in spaces in order to clear the spinner if required.