Documentation
¶
Overview ¶
Package spinner provides a customizable terminal spinner for displaying progress or activity.
Index ¶
- Constants
- Variables
- func Color256(n int) string
- func ColorPulse(start, end int, duration time.Duration) func() string
- func GreyPulse(interval time.Duration) func() string
- func SpeedupInterval(start, end, duration time.Duration) func() time.Duration
- func WithColor(color string) func(*Spinner)
- func WithColorFunc(f func() string) func(*Spinner)
- func WithHideCursor(hide bool) func(*Spinner)
- func WithIntervalFunc(f func() time.Duration) func(*Spinner)
- type Option
- type Spinner
Examples ¶
Constants ¶
View Source
const ( Black = "\033[38;5;0m" Green = "\033[38;5;2m" Olive = "\033[38;5;3m" Teal = "\033[38;5;6m" Silver = "\033[38;5;7m" Grey = "\033[38;5;8m" Red = "\033[38;5;9m" Lime = "\033[38;5;10m" Yellow = "\033[38;5;11m" Blue = "\033[38;5;12m" Aqua = "\033[38;5;14m" White = "\033[38;5;15m" Reset = "\033[0m" )
Variables ¶
View Source
var ( Dots1 = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"} Dots2 = []string{"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"} Dots3 = []string{"⠋", "⠙", "⠚", "⠞", "⠖", "⠦", "⠴", "⠲", "⠳", "⠓"} Dots4 = []string{"⠄", "⠆", "⠇", "⠋", "⠙", "⠸", "⠰", "⠠", "⠰", "⠸", "⠙", "⠋", "⠇", "⠆"} Dots5 = []string{"⠋", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋"} Dots6 = []string{"⠁", "⠉", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠤", "⠄", "⠄", "⠤", "⠴", "⠲", "⠒", "⠂", "⠂", "⠒", "⠚", "⠙", "⠉", "⠁"} Dots7 = []string{"⠈", "⠉", "⠋", "⠓", "⠒", "⠐", "⠐", "⠒", "⠖", "⠦", "⠤", "⠠", "⠠", "⠤", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋", "⠉", "⠈"} Dots8 = []string{"⠁", "⠁", "⠉", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠤", "⠄", "⠄", "⠤", "⠠", "⠠", "⠤", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋", "⠉", "⠈", "⠈"} Dots9 = []string{"⢹", "⢺", "⢼", "⣸", "⣇", "⡧", "⡗", "⡏"} Dots10 = []string{"⢄", "⢂", "⢁", "⡁", "⡈", "⡐", "⡠"} Dots11 = []string{"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"} Dots12 = []string{"⢀⠀", "⡀⠀", "⠄⠀", "⢂⠀", "⡂⠀", "⠅⠀", "⢃⠀", "⡃⠀", "⠍⠀", "⢋⠀", "⡋⠀", "⠍⠁", "⢋⠁", "⡋⠁", "⠍⠉", "⠋⠉", "⠋⠉", "⠉⠙", "⠉⠙", "⠉⠩", "⠈⢙", "⠈⡙", "⢈⠩", "⡀⢙", "⠄⡙", "⢂⠩", "⡂⢘", "⠅⡘", "⢃⠨", "⡃⢐", "⠍⡐", "⢋⠠", "⡋⢀", "⠍⡁", "⢋⠁", "⡋⠁", "⠍⠉", "⠋⠉", "⠋⠉", "⠉⠙", "⠉⠙", "⠉⠩", "⠈⢙", "⠈⡙", "⠈⠩", "⠀⢙", "⠀⡙", "⠀⠩", "⠀⢘", "⠀⡘", "⠀⠨", "⠀⢐", "⠀⡐", "⠀⠠", "⠀⢀", "⠀⡀"} Line = []string{"-", "\\", "|", "/"} Pipe = []string{"┤", "┘", "┴", "└", "├", "┌", "┬", "┐"} SimpleDots = []string{". ", ".. ", "...", " "} SimpleDotsScrolling = []string{". ", ".. ", "...", " ..", " .", " "} Star = []string{"✶", "✸", "✹", "✺", "✹", "✷"} Flip = []string{"_", "_", "_", "-", "`", "`", "'", "´", "-", "_", "_", "_"} Hamburger = []string{"☱", "☲", "☴"} GrowVertical = []string{"▁", "▃", "▄", "▅", "▆", "▇", "▆", "▅", "▄", "▃"} GrowHorizontal = []string{"▏", "▎", "▍", "▌", "▋", "▊", "▉", "▊", "▋", "▌", "▍", "▎"} Balloon = []string{" ", ".", "o", "O", "@", "*", " "} Noise = []string{"▓", "▒", "░"} Bounce = []string{"⠁", "⠂", "⠄", "⠂"} BoxBounce = []string{"▖", "▘", "▝", "▗"} BoxBounce2 = []string{"▌", "▀", "▐", "▄"} Triangle = []string{"◢", "◣", "◤", "◥"} Arc = []string{"◜", "◠", "◝", "◞", "◡", "◟"} Circle = []string{"◡", "⊙", "◠"} SquareCorners = []string{"◰", "◳", "◲", "◱"} CircleQuarters = []string{"◴", "◷", "◶", "◵"} CircleHalves = []string{"◐", "◓", "◑", "◒"} Moon = []string{"🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘"} Smiley = []string{"😄 ", "😝 "} Monkey = []string{"🙈 ", "🙈 ", "🙉 ", "🙊 "} Hearts = []string{"💛 ", "💙 ", "💜 ", "💚 ", "❤️ "} Clock = []string{"🕛 ", "🕐 ", "🕑 ", "🕒 ", "🕓 ", "🕔 ", "🕕 ", "🕖 ", "🕗 ", "🕘 ", "🕙 ", "🕚 "} Earth = []string{"🌍 ", "🌎 ", "🌏 "} Material = []string{"█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁", "██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁", "███▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁", "████▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁", "██████▁▁▁▁▁▁▁▁▁▁▁▁▁▁", "██████▁▁▁▁▁▁▁▁▁▁▁▁▁▁", "███████▁▁▁▁▁▁▁▁▁▁▁▁▁", "████████▁▁▁▁▁▁▁▁▁▁▁▁", "█████████▁▁▁▁▁▁▁▁▁▁▁", "█████████▁▁▁▁▁▁▁▁▁▁▁", "██████████▁▁▁▁▁▁▁▁▁▁", "███████████▁▁▁▁▁▁▁▁▁", "█████████████▁▁▁▁▁▁▁", "██████████████▁▁▁▁▁▁", "██████████████▁▁▁▁▁▁", "▁██████████████▁▁▁▁▁", "▁██████████████▁▁▁▁▁", "▁██████████████▁▁▁▁▁", "▁▁██████████████▁▁▁▁", "▁▁▁██████████████▁▁▁", "▁▁▁▁█████████████▁▁▁", "▁▁▁▁██████████████▁▁", "▁▁▁▁██████████████▁▁", "▁▁▁▁▁██████████████▁", "▁▁▁▁▁██████████████▁", "▁▁▁▁▁██████████████▁", "▁▁▁▁▁▁██████████████", "▁▁▁▁▁▁██████████████", "▁▁▁▁▁▁▁█████████████", "▁▁▁▁▁▁▁█████████████", "▁▁▁▁▁▁▁▁████████████", "▁▁▁▁▁▁▁▁████████████", "▁▁▁▁▁▁▁▁▁███████████", "▁▁▁▁▁▁▁▁▁███████████", "▁▁▁▁▁▁▁▁▁▁██████████", "▁▁▁▁▁▁▁▁▁▁██████████", "▁▁▁▁▁▁▁▁▁▁▁▁████████", "▁▁▁▁▁▁▁▁▁▁▁▁▁███████", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁██████", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████", "█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████", "██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███", "██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███", "███▁▁▁▁▁▁▁▁▁▁▁▁▁▁███", "████▁▁▁▁▁▁▁▁▁▁▁▁▁▁██", "█████▁▁▁▁▁▁▁▁▁▁▁▁▁▁█", "█████▁▁▁▁▁▁▁▁▁▁▁▁▁▁█", "██████▁▁▁▁▁▁▁▁▁▁▁▁▁█", "████████▁▁▁▁▁▁▁▁▁▁▁▁", "█████████▁▁▁▁▁▁▁▁▁▁▁", "█████████▁▁▁▁▁▁▁▁▁▁▁", "█████████▁▁▁▁▁▁▁▁▁▁▁", "█████████▁▁▁▁▁▁▁▁▁▁▁", "███████████▁▁▁▁▁▁▁▁▁", "████████████▁▁▁▁▁▁▁▁", "████████████▁▁▁▁▁▁▁▁", "██████████████▁▁▁▁▁▁", "██████████████▁▁▁▁▁▁", "▁██████████████▁▁▁▁▁", "▁██████████████▁▁▁▁▁", "▁▁▁█████████████▁▁▁▁", "▁▁▁▁▁████████████▁▁▁", "▁▁▁▁▁████████████▁▁▁", "▁▁▁▁▁▁███████████▁▁▁", "▁▁▁▁▁▁▁▁█████████▁▁▁", "▁▁▁▁▁▁▁▁█████████▁▁▁", "▁▁▁▁▁▁▁▁▁█████████▁▁", "▁▁▁▁▁▁▁▁▁█████████▁▁", "▁▁▁▁▁▁▁▁▁▁█████████▁", "▁▁▁▁▁▁▁▁▁▁▁████████▁", "▁▁▁▁▁▁▁▁▁▁▁████████▁", "▁▁▁▁▁▁▁▁▁▁▁▁███████▁", "▁▁▁▁▁▁▁▁▁▁▁▁███████▁", "▁▁▁▁▁▁▁▁▁▁▁▁▁███████", "▁▁▁▁▁▁▁▁▁▁▁▁▁███████", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁", "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁"} )
Spinner styles
Functions ¶
func SpeedupInterval ¶ added in v0.1.1
func WithColorFunc ¶
WithColorFunc sets a function to determine the color for the spinner.
func WithHideCursor ¶
WithHideCursor sets whether to hide the cursor while the spinner is active.
func WithIntervalFunc ¶
WithIntervalFunc sets a function to determine the interval for the spinner.
Types ¶
type Option ¶
type Option func(*Spinner)
Option is a function that configures a Spinner.
func WithFrames ¶
WithFrames sets the frames for the spinner.
func WithInterval ¶
WithInterval sets a fixed interval for the spinner.
func WithPosition ¶ added in v0.1.2
WithPosition sets the position of the spinner.
func WithPrefix ¶ added in v0.1.4
WithPrefix sets a prefix for the spinner.
func WithSuffix ¶ added in v0.1.4
WithSuffix sets a suffix for the spinner.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner represents a terminal spinner.
Example (Basic) ¶
package main import ( "time" "github.com/tmc/spinner" ) func main() { s := spinner.New() s.Start() time.Sleep(time.Second) s.Stop() }
Example (WithAdvancedOptions) ¶
package main import ( "time" "github.com/tmc/spinner" ) func main() { s := spinner.New( spinner.WithFrames(spinner.Dots8), spinner.WithIntervalFunc( spinner.SpeedupInterval(90*time.Millisecond, 40*time.Millisecond, time.Second*5), ), spinner.WithColorFunc(spinner.GreyPulse(15*time.Millisecond)), ) s.Start() time.Sleep(5 * time.Second) s.Stop() }
Example (WithCustomFrames) ¶
package main import ( "time" "github.com/tmc/spinner" ) func main() { s := spinner.New(spinner.WithFrames(spinner.Dots12)) s.Start() time.Sleep(3 * time.Second) s.Stop() }
Example (WithCustomFramesAllDots) ¶
package main import ( "fmt" "os" "time" "github.com/tmc/spinner" ) func main() { for i, f := range [][]string{ spinner.Dots1, spinner.Dots2, spinner.Dots3, spinner.Dots4, spinner.Dots5, spinner.Dots6, spinner.Dots7, spinner.Dots8, spinner.Dots9, spinner.Dots10, spinner.Dots11, spinner.Dots12, } { s := spinner.New(spinner.WithFrames(f)) fmt.Fprintf(os.Stderr, "spinner.Dots%v\n", i+1) s.Start() time.Sleep(2 * time.Second) s.Stop() fmt.Fprintf(os.Stderr, "\n") } }
Example (WithPrefixOptions) ¶
package main import ( "time" "github.com/tmc/spinner" ) func main() { prefixes := []string{ "🚀 ", "\033[31mError:\033[0m ", "Loading: ", } for _, prefix := range prefixes { s := spinner.New( spinner.WithPrefix(prefix), spinner.WithFrames([]string{"▁", "▂", "▃"}), spinner.WithInterval(20*time.Millisecond), ) s.Start() time.Sleep(900 * time.Millisecond) s.Stop() } }
Click to show internal directories.
Click to hide internal directories.