package spinner
import "git.sr.ht/~poldi1405/go-indicators/spinner"
Package spinner allows creating and using spinners that indicate that a
process is working in the background.
This function pretty much shows all you need for using a spinner:
Code:
This shows how to use multiple different spinners at once.
Code:
This shows the same spinner 3 times and cleans up afterwards
Code:
Example¶
{
var s Spinner
s.SetStyle("dots")
for i := 0; i < 100; i++ {
fmt.Printf("\rworking%v", s.Next())
time.Sleep(80 * time.Millisecond)
}
}
Example (MultipleSpinner)¶
{
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())
}
Example (Multiuse)¶
{
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())
}
Index ¶
Examples ¶
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.
func (*Spinner) Current ¶
Current returns the current character for the spinner
func (*Spinner) Next ¶
Next returns the next character for the spinner
func (*Spinner) SetStyle ¶
SetStyle loads a style into the spinner
Source Files ¶
- Version
- v1.2.0 (latest)
- Published
- Apr 16, 2023
- Platform
- linux/amd64
- Imports
- 3 packages
- Last checked
- 2 weeks ago –
Tools for package owners.