Documentation
¶
Overview ¶
Package yacspin provides Yet Another CLi Spinner for Go, taking inspiration (and some utility code) from the https://github.com/briandowns/spinner project. Specifically this project borrows the default character sets, and color mappings to github.com/fatih/color colors, from that project.
Within the yacspin package there are some default spinners stored in the yacspin.CharSets variable, but you can also provide your own. There is also a list of known colors in the yacspin.ValidColors variable.
cfg := yacspin.Config{ Delay: 100 * time.Millisecond, CharSet: yacspin.CharSets[59], Suffix: " backing up database to S3", Message: "exporting data", StopCharacter: "✓", StopColors: []string{"fgGreen"}, } spinner, err := yacspin.New(cfg) // handle the error spinner.Start() // doing some work time.Sleep(2 * time.Second) spinner.Message("uploading data") // upload... time.Sleep(2 * time.Second) spinner.Stop()
Index ¶
- Variables
- type Config
- type Spinner
- func (s *Spinner) Active() bool
- func (s *Spinner) CharSet(cs []string)
- func (s *Spinner) Colors(colors ...string) error
- func (s *Spinner) Delay(d time.Duration) error
- func (s *Spinner) Message(message string)
- func (s *Spinner) Prefix(prefix string)
- func (s *Spinner) Reverse()
- func (s *Spinner) Start() error
- func (s *Spinner) Stop() error
- func (s *Spinner) StopCharacter(char string)
- func (s *Spinner) StopColors(colors ...string) error
- func (s *Spinner) StopMessage(message string)
- func (s *Spinner) Suffix(suffix string)
Constants ¶
This section is empty.
Variables ¶
var CharSets = map[int][]string{
0: {"←", "↖", "↑", "↗", "→", "↘", "↓", "↙"},
1: {"▁", "▃", "▄", "▅", "▆", "▇", "█", "▇", "▆", "▅", "▄", "▃", "▁"},
2: {"▖", "▘", "▝", "▗"},
3: {"┤", "┘", "┴", "└", "├", "┌", "┬", "┐"},
4: {"◢", "◣", "◤", "◥"},
5: {"◰", "◳", "◲", "◱"},
6: {"◴", "◷", "◶", "◵"},
7: {"◐", "◓", "◑", "◒"},
8: {".", "o", "O", "@", "*"},
9: {"|", "/", "-", "\\"},
10: {"◡◡", "⊙⊙", "◠◠"},
11: {"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"},
12: {">))'>", " >))'>", " >))'>", " >))'>", " >))'>", " <'((<", " <'((<", " <'((<"},
13: {"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"},
14: {"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"},
15: {"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"},
16: {"▉", "▊", "▋", "▌", "▍", "▎", "▏", "▎", "▍", "▌", "▋", "▊", "▉"},
17: {"■", "□", "▪", "▫"},
18: {"←", "↑", "→", "↓"},
19: {"╫", "╪"},
20: {"⇐", "⇖", "⇑", "⇗", "⇒", "⇘", "⇓", "⇙"},
21: {"⠁", "⠁", "⠉", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠤", "⠄", "⠄", "⠤", "⠠", "⠠", "⠤", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋", "⠉", "⠈", "⠈"},
22: {"⠈", "⠉", "⠋", "⠓", "⠒", "⠐", "⠐", "⠒", "⠖", "⠦", "⠤", "⠠", "⠠", "⠤", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋", "⠉", "⠈"},
23: {"⠁", "⠉", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠤", "⠄", "⠄", "⠤", "⠴", "⠲", "⠒", "⠂", "⠂", "⠒", "⠚", "⠙", "⠉", "⠁"},
24: {"⠋", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋"},
25: {"ヲ", "ァ", "ィ", "ゥ", "ェ", "ォ", "ャ", "ュ", "ョ", "ッ", "ア", "イ", "ウ", "エ", "オ", "カ", "キ", "ク", "ケ", "コ", "サ", "シ", "ス", "セ", "ソ", "タ", "チ", "ツ", "テ", "ト", "ナ", "ニ", "ヌ", "ネ", "ノ", "ハ", "ヒ", "フ", "ヘ", "ホ", "マ", "ミ", "ム", "メ", "モ", "ヤ", "ユ", "ヨ", "ラ", "リ", "ル", "レ", "ロ", "ワ", "ン"},
26: {".", "..", "..."},
27: {"▁", "▂", "▃", "▄", "▅", "▆", "▇", "█", "▉", "▊", "▋", "▌", "▍", "▎", "▏", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█", "▇", "▆", "▅", "▄", "▃", "▂", "▁"},
28: {".", "o", "O", "°", "O", "o", "."},
29: {"+", "x"},
30: {"v", "<", "^", ">"},
31: {">>--->", " >>--->", " >>--->", " >>--->", " >>--->", " <---<<", " <---<<", " <---<<", " <---<<", "<---<<"},
32: {"|", "||", "|||", "||||", "|||||", "|||||||", "||||||||", "|||||||", "||||||", "|||||", "||||", "|||", "||", "|"},
33: {"[ ]", "[= ]", "[== ]", "[=== ]", "[==== ]", "[===== ]", "[====== ]", "[======= ]", "[======== ]", "[========= ]", "[==========]"},
34: {"(*---------)", "(-*--------)", "(--*-------)", "(---*------)", "(----*-----)", "(-----*----)", "(------*---)", "(-------*--)", "(--------*-)", "(---------*)"},
35: {"█▒▒▒▒▒▒▒▒▒", "███▒▒▒▒▒▒▒", "█████▒▒▒▒▒", "███████▒▒▒", "██████████"},
36: {"[ ]", "[=> ]", "[===> ]", "[=====> ]", "[======> ]", "[========> ]", "[==========> ]", "[============> ]", "[==============> ]", "[================> ]", "[==================> ]", "[===================>]"},
39: {"🌍", "🌎", "🌏"},
40: {"◜", "◝", "◞", "◟"},
41: {"⬒", "⬔", "⬓", "⬕"},
42: {"⬖", "⬘", "⬗", "⬙"},
43: {"[>>> >]", "[]>>>> []", "[] >>>> []", "[] >>>> []", "[] >>>> []", "[] >>>>[]", "[>> >>]"},
44: {"♠", "♣", "♥", "♦"},
45: {"➞", "➟", "➠", "➡", "➠", "➟"},
46: {" | ", ` \ `, "_ ", ` \ `, " | ", " / ", " _", " / "},
47: {" . . . .", ". . . .", ". . . .", ". . . .", ". . . . ", ". . . . ."},
48: {" | ", " / ", " _ ", ` \ `, " | ", ` \ `, " _ ", " / "},
49: {"⎺", "⎻", "⎼", "⎽", "⎼", "⎻"},
50: {"▹▹▹▹▹", "▸▹▹▹▹", "▹▸▹▹▹", "▹▹▸▹▹", "▹▹▹▸▹", "▹▹▹▹▸"},
51: {"[ ]", "[ =]", "[ ==]", "[ ===]", "[====]", "[=== ]", "[== ]", "[= ]"},
52: {"( ● )", "( ● )", "( ● )", "( ● )", "( ●)", "( ● )", "( ● )", "( ● )", "( ● )"},
53: {"✶", "✸", "✹", "✺", "✹", "✷"},
54: {"▐|\\____________▌", "▐_|\\___________▌", "▐__|\\__________▌", "▐___|\\_________▌", "▐____|\\________▌", "▐_____|\\_______▌", "▐______|\\______▌", "▐_______|\\_____▌", "▐________|\\____▌", "▐_________|\\___▌", "▐__________|\\__▌", "▐___________|\\_▌", "▐____________|\\▌", "▐____________/|▌", "▐___________/|_▌", "▐__________/|__▌", "▐_________/|___▌", "▐________/|____▌", "▐_______/|_____▌", "▐______/|______▌", "▐_____/|_______▌", "▐____/|________▌", "▐___/|_________▌", "▐__/|__________▌", "▐_/|___________▌", "▐/|____________▌"},
55: {"▐⠂ ▌", "▐⠈ ▌", "▐ ⠂ ▌", "▐ ⠠ ▌", "▐ ⡀ ▌", "▐ ⠠ ▌", "▐ ⠂ ▌", "▐ ⠈ ▌", "▐ ⠂ ▌", "▐ ⠠ ▌", "▐ ⡀ ▌", "▐ ⠠ ▌", "▐ ⠂ ▌", "▐ ⠈ ▌", "▐ ⠂▌", "▐ ⠠▌", "▐ ⡀▌", "▐ ⠠ ▌", "▐ ⠂ ▌", "▐ ⠈ ▌", "▐ ⠂ ▌", "▐ ⠠ ▌", "▐ ⡀ ▌", "▐ ⠠ ▌", "▐ ⠂ ▌", "▐ ⠈ ▌", "▐ ⠂ ▌", "▐ ⠠ ▌", "▐ ⡀ ▌", "▐⠠ ▌"},
56: {"¿", "?"},
57: {"⢹", "⢺", "⢼", "⣸", "⣇", "⡧", "⡗", "⡏"},
58: {"⢄", "⢂", "⢁", "⡁", "⡈", "⡐", "⡠"},
59: {". ", ".. ", "...", " ..", " .", " "},
60: {".", "o", "O", "°", "O", "o", "."},
61: {"▓", "▒", "░"},
62: {"▌", "▀", "▐", "▄"},
63: {"⊶", "⊷"},
64: {"▪", "▫"},
65: {"□", "■"},
66: {"▮", "▯"},
67: {"-", "=", "≡"},
68: {"d", "q", "p", "b"},
69: {"∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙"},
70: {"🌑 ", "🌒 ", "🌓 ", "🌔 ", "🌕 ", "🌖 ", "🌗 ", "🌘 "},
71: {"☗", "☖"},
72: {"⧇", "⧆"},
73: {"◉", "◎"},
74: {"㊂", "㊀", "㊁"},
75: {"⦾", "⦿"},
76: {"ဝ", "၀"},
77: {"▌", "▀", "▐▄"},
}
CharSets contains the default character sets from https://github.com/briandowns/spinner.
var ValidColors = map[string]struct{}{
"black": struct{}{},
"red": struct{}{},
"green": struct{}{},
"yellow": struct{}{},
"blue": struct{}{},
"magenta": struct{}{},
"cyan": struct{}{},
"white": struct{}{},
"reset": struct{}{},
"bold": struct{}{},
"faint": struct{}{},
"italic": struct{}{},
"underline": struct{}{},
"blinkslow": struct{}{},
"blinkrapid": struct{}{},
"reversevideo": struct{}{},
"concealed": struct{}{},
"crossedout": struct{}{},
"fgBlack": struct{}{},
"fgRed": struct{}{},
"fgGreen": struct{}{},
"fgYellow": struct{}{},
"fgBlue": struct{}{},
"fgMagenta": struct{}{},
"fgCyan": struct{}{},
"fgWhite": struct{}{},
"fgHiBlack": struct{}{},
"fgHiRed": struct{}{},
"fgHiGreen": struct{}{},
"fgHiYellow": struct{}{},
"fgHiBlue": struct{}{},
"fgHiMagenta": struct{}{},
"fgHiCyan": struct{}{},
"fgHiWhite": struct{}{},
"bgBlack": struct{}{},
"bgRed": struct{}{},
"bgGreen": struct{}{},
"bgYellow": struct{}{},
"bgBlue": struct{}{},
"bgMagenta": struct{}{},
"bgCyan": struct{}{},
"bgWhite": struct{}{},
"bgHiBlack": struct{}{},
"bgHiRed": struct{}{},
"bgHiGreen": struct{}{},
"bgHiYellow": struct{}{},
"bgHiBlue": struct{}{},
"bgHiMagenta": struct{}{},
"bgHiCyan": struct{}{},
"bgHiWhite": struct{}{},
}
ValidColors holds the list of the strings that are mapped to github.com/fatih/color color attributes. Any of these colors / attributes can be used with the *Spinner type.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Delay specifies how long to way between repainting the line. Optimal // value depends on the character set you use. // // Note: This is a required value (cannot be 0) Delay time.Duration // Writer is the place where we are outputting the spinner, and can't be // changed on the fly. If omitted, this defaults to os.Stdout. Writer io.Writer // ColorAll describes whether to color everything (all) or just the spinner // character(s). This cannot be changed. ColorAll bool // Colors are the colors sued for the different printed messages. This // respects the ColorAll field. Colors []string // CharSet is the list of characters to iterate through to draw the spinner. CharSet []string // Prefix is the string printed immediately before the spinner. Prefix string // Suffix is the string printed immediately after the spinner. It's // recommended that this string starts with an space ` ` character. Suffix string // Message is the string printed after the suffix. If a suffix is present, // `: ` is appended to the suffix before printing the message. It results in // a message like: // // <prefix><spinner><suffix>: <message> Message string // StopMessage is the message used when Stop() is called. StopMessage string // StopCharacter is spinner character used when Stop() is called. // Recommended character is `✓`. StopCharacter string // StopColors are the colors used for the Stop() printed line. This respects // the ColorAll field. StopColors []string }
Config is the configuration structure for the Spinner.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner is the struct type representing a spinner. It's configured via the Config type, and controlled via its methods. Some configuration can also be updated via methods.
Note: You need to use New() to construct a *Spinner.
func (*Spinner) Active ¶
Active returns whether the spinner is active. Active means the spinner is either starting or running.
func (*Spinner) CharSet ¶
CharSet updates the set of characters (strings) to use for the spinner. You can provide your own, or use one from the CharSets variable.
The character sets available in the CharSets variable are from the https://github.com/briandowns/spinner project.
func (*Spinner) Colors ¶
Colors updates the github.com/fatih/colors for printing the spinner line. ColorAll config parameter controls whether only the spinner character is printed with these colors, or the whole line.
StopColors() is the method to control the colors in the stop message.
func (*Spinner) Reverse ¶
func (s *Spinner) Reverse()
Reverse flips the character set order of the spinner characters.
func (*Spinner) Start ¶
Start begins the spinner on the Writer in the Config provided to New(). Onnly possible error is if the spinner is already runninng.
func (*Spinner) Stop ¶
Stop disables the spinner, and prints the StopCharacter with the StopMessage using the StopColors. This blocks until the stopped message is printed. Only possible error is if the spinner is not running.
func (*Spinner) StopCharacter ¶
StopCharacter sets the single "character" to use for the spinner. Recommended character is `✓`.
func (*Spinner) StopColors ¶
StopColors updates the colors used for the stop message. See Colors() method documentation for more context.
func (*Spinner) StopMessage ¶
StopMessage updates the Message used when Stop() is called.