spinner

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package spinner provides animated spinner widgets.

Index

Constants

View Source
const Default = "dots"

Default is the default spinner name.

Variables

View Source
var Spinners = map[string]Definition{
	"dots": {
		Interval: 80 * time.Millisecond,
		Frames:   []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"},
	},
	"dots2": {
		Interval: 80 * time.Millisecond,
		Frames:   []string{"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"},
	},
	"dots3": {
		Interval: 80 * time.Millisecond,
		Frames:   []string{"⠋", "⠙", "⠚", "⠞", "⠖", "⠦", "⠴", "⠲", "⠳", "⠓"},
	},
	"dots9": {
		Interval: 80 * time.Millisecond,
		Frames:   []string{"⢹", "⢺", "⢼", "⣸", "⣇", "⡧", "⡗", "⡏"},
	},
	"dots11": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"},
	},
	"line": {
		Interval: 130 * time.Millisecond,
		Frames:   []string{"-", "\\", "|", "/"},
	},
	"line2": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"⠂", "-", "–", "—", "–", "-"},
	},
	"pipe": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"┤", "┘", "┴", "└", "├", "┌", "┬", "┐"},
	},
	"simpleDots": {
		Interval: 400 * time.Millisecond,
		Frames:   []string{".  ", ".. ", "...", "   "},
	},
	"simpleDotsScrolling": {
		Interval: 200 * time.Millisecond,
		Frames:   []string{".  ", ".. ", "...", " ..", "  .", "   "},
	},
	"star": {
		Interval: 70 * time.Millisecond,
		Frames:   []string{"✶", "✸", "✹", "✺", "✹", "✷"},
	},
	"star2": {
		Interval: 80 * time.Millisecond,
		Frames:   []string{"+", "x", "*"},
	},
	"flip": {
		Interval: 70 * time.Millisecond,
		Frames:   []string{"_", "_", "_", "-", "`", "`", "'", "´", "-", "_", "_", "_"},
	},
	"hamburger": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"☱", "☲", "☴"},
	},
	"growVertical": {
		Interval: 120 * time.Millisecond,
		Frames:   []string{"▁", "▃", "▄", "▅", "▆", "▇", "▆", "▅", "▄", "▃"},
	},
	"growHorizontal": {
		Interval: 120 * time.Millisecond,
		Frames:   []string{"▏", "▎", "▍", "▌", "▋", "▊", "▉", "▊", "▋", "▌", "▍", "▎"},
	},
	"balloon": {
		Interval: 140 * time.Millisecond,
		Frames:   []string{" ", ".", "o", "O", "@", "*", " "},
	},
	"balloon2": {
		Interval: 120 * time.Millisecond,
		Frames:   []string{".", "o", "O", "°", "O", "o", "."},
	},
	"noise": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"▓", "▒", "░"},
	},
	"bounce": {
		Interval: 120 * time.Millisecond,
		Frames:   []string{"⠁", "⠂", "⠄", "⠂"},
	},
	"boxBounce": {
		Interval: 120 * time.Millisecond,
		Frames:   []string{"▖", "▘", "▝", "▗"},
	},
	"boxBounce2": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"▌", "▀", "▐", "▄"},
	},
	"triangle": {
		Interval: 50 * time.Millisecond,
		Frames:   []string{"◢", "◣", "◤", "◥"},
	},
	"arc": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"◜", "◠", "◝", "◞", "◡", "◟"},
	},
	"circle": {
		Interval: 120 * time.Millisecond,
		Frames:   []string{"◡", "⊙", "◠"},
	},
	"squareCorners": {
		Interval: 180 * time.Millisecond,
		Frames:   []string{"◰", "◳", "◲", "◱"},
	},
	"circleQuarters": {
		Interval: 120 * time.Millisecond,
		Frames:   []string{"◴", "◷", "◶", "◵"},
	},
	"circleHalves": {
		Interval: 50 * time.Millisecond,
		Frames:   []string{"◐", "◓", "◑", "◒"},
	},
	"squish": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"╫", "╪"},
	},
	"toggle": {
		Interval: 250 * time.Millisecond,
		Frames:   []string{"⊶", "⊷"},
	},
	"toggle2": {
		Interval: 80 * time.Millisecond,
		Frames:   []string{"▫", "▪"},
	},
	"toggle3": {
		Interval: 120 * time.Millisecond,
		Frames:   []string{"□", "■"},
	},
	"toggle4": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"■", "□", "▪", "▫"},
	},
	"toggle5": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"▮", "▯"},
	},
	"toggle6": {
		Interval: 300 * time.Millisecond,
		Frames:   []string{"ဝ", "၀"},
	},
	"toggle7": {
		Interval: 80 * time.Millisecond,
		Frames:   []string{"⦾", "⦿"},
	},
	"toggle8": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"◍", "◌"},
	},
	"toggle9": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"◉", "◎"},
	},
	"toggle10": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"㊂", "㊀", "㊁"},
	},
	"toggle11": {
		Interval: 50 * time.Millisecond,
		Frames:   []string{"⧇", "⧆"},
	},
	"toggle12": {
		Interval: 120 * time.Millisecond,
		Frames:   []string{"☗", "☖"},
	},
	"toggle13": {
		Interval: 80 * time.Millisecond,
		Frames:   []string{"=", "*", "-"},
	},
	"arrow": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"←", "↖", "↑", "↗", "→", "↘", "↓", "↙"},
	},
	"arrow2": {
		Interval: 80 * time.Millisecond,
		Frames:   []string{"⬆️ ", "↗️ ", "➡️ ", "↘️ ", "⬇️ ", "↙️ ", "⬅️ ", "↖️ "},
	},
	"arrow3": {
		Interval: 120 * time.Millisecond,
		Frames:   []string{"▹▹▹▹▹", "▸▹▹▹▹", "▹▸▹▹▹", "▹▹▸▹▹", "▹▹▹▸▹", "▹▹▹▹▸"},
	},
	"bouncingBar": {
		Interval: 80 * time.Millisecond,
		Frames: []string{
			"[    ]", "[=   ]", "[==  ]", "[=== ]", "[ ===]", "[  ==]",
			"[   =]", "[    ]", "[   =]", "[  ==]", "[ ===]", "[====]",
			"[=== ]", "[==  ]", "[=   ]",
		},
	},
	"bouncingBall": {
		Interval: 80 * time.Millisecond,
		Frames: []string{
			"( ●    )", "(  ●   )", "(   ●  )", "(    ● )", "(     ●)",
			"(    ● )", "(   ●  )", "(  ●   )", "( ●    )", "(●     )",
		},
	},
	"smiley": {
		Interval: 200 * time.Millisecond,
		Frames:   []string{"😄 ", "😝 "},
	},
	"monkey": {
		Interval: 300 * time.Millisecond,
		Frames:   []string{"🙈 ", "🙈 ", "🙉 ", "🙊 "},
	},
	"hearts": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"💛 ", "💙 ", "💜 ", "💚 ", "❤️ "},
	},
	"clock": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"🕛 ", "🕐 ", "🕑 ", "🕒 ", "🕓 ", "🕔 ", "🕕 ", "🕖 ", "🕗 ", "🕘 ", "🕙 ", "🕚 "},
	},
	"earth": {
		Interval: 180 * time.Millisecond,
		Frames:   []string{"🌍 ", "🌎 ", "🌏 "},
	},
	"moon": {
		Interval: 80 * time.Millisecond,
		Frames:   []string{"🌑 ", "🌒 ", "🌓 ", "🌔 ", "🌕 ", "🌖 ", "🌗 ", "🌘 "},
	},
	"runner": {
		Interval: 140 * time.Millisecond,
		Frames:   []string{"🚶 ", "🏃 "},
	},
	"pong": {
		Interval: 80 * time.Millisecond,
		Frames: []string{
			"▐⠂       ▌", "▐⠈       ▌", "▐ ⠂      ▌", "▐ ⠠      ▌",
			"▐  ⡀     ▌", "▐  ⠠     ▌", "▐   ⠂    ▌", "▐   ⠈    ▌",
			"▐    ⠂   ▌", "▐    ⠠   ▌", "▐     ⡀  ▌", "▐     ⠠  ▌",
			"▐      ⠂ ▌", "▐      ⠈ ▌", "▐       ⠂▌", "▐       ⠠▌",
			"▐       ⡀▌", "▐      ⠠ ▌", "▐      ⠂ ▌", "▐     ⠈  ▌",
			"▐     ⠂  ▌", "▐    ⠠   ▌", "▐    ⡀   ▌", "▐   ⠠    ▌",
			"▐   ⠂    ▌", "▐  ⠈     ▌", "▐  ⠂     ▌", "▐ ⠠      ▌",
			"▐ ⡀      ▌", "▐⠠       ▌",
		},
	},
	"shark": {
		Interval: 120 * time.Millisecond,
		Frames: []string{
			"▐|\\____________▌", "▐_|\\___________▌", "▐__|\\__________▌",
			"▐___|\\_________▌", "▐____|\\________▌", "▐_____|\\_______▌",
			"▐______|\\______▌", "▐_______|\\_____▌", "▐________|\\____▌",
			"▐_________|\\___▌", "▐__________|\\__▌", "▐___________|\\_▌",
			"▐____________|\\▌", "▐____________/|▌", "▐___________/|_▌",
			"▐__________/|__▌", "▐_________/|___▌", "▐________/|____▌",
			"▐_______/|_____▌", "▐______/|______▌", "▐_____/|_______▌",
			"▐____/|________▌", "▐___/|_________▌", "▐__/|__________▌",
			"▐_/|___________▌", "▐/|____________▌",
		},
	},
	"dqpb": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"d", "q", "p", "b"},
	},
	"weather": {
		Interval: 100 * time.Millisecond,
		Frames:   []string{"☀️ ", "☀️ ", "☀️ ", "🌤 ", "⛅️ ", "🌥 ", "☁️ ", "🌧 ", "🌨 ", "🌧 ", "🌨 ", "🌧 ", "🌨 ", "⛈ ", "🌨 ", "🌧 ", "🌨 ", "☁️ ", "🌥 ", "⛅️ ", "🌤 ", "☀️ ", "☀️ "},
	},
	"christmas": {
		Interval: 400 * time.Millisecond,
		Frames:   []string{"🌲", "🎄"},
	},
	"grenade": {
		Interval: 80 * time.Millisecond,
		Frames: []string{
			"،  ", "′  ", " ´ ", " ‾ ", "  ⸌", "  ⸊", "  |", "  ⁎",
			"  ⁕", " ෴ ", "  ⁓", "   ", "   ", "   ",
		},
	},
	"point": {
		Interval: 125 * time.Millisecond,
		Frames:   []string{"∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙"},
	},
	"layer": {
		Interval: 150 * time.Millisecond,
		Frames:   []string{"-", "=", "≡"},
	},
	"betaWave": {
		Interval: 80 * time.Millisecond,
		Frames: []string{
			"ρββββββ", "βρβββββ", "ββρββββ", "βββρβββ",
			"ββββρββ", "βββββρβ", "ββββββρ",
		},
	},
	"aesthetic": {
		Interval: 80 * time.Millisecond,
		Frames: []string{
			"▰▱▱▱▱▱▱", "▰▰▱▱▱▱▱", "▰▰▰▱▱▱▱", "▰▰▰▰▱▱▱",
			"▰▰▰▰▰▱▱", "▰▰▰▰▰▰▱", "▰▰▰▰▰▰▰", "▰▱▱▱▱▱▱",
		},
	},
}

Spinners contains all available spinner definitions. Sourced from cli-spinners (MIT License, Sindre Sorhus).

Functions

func Names

func Names() []string

Names returns all available spinner names in sorted order.

Types

type Definition

type Definition struct {
	Interval time.Duration
	Frames   []string
}

Definition describes a spinner animation.

func Get

func Get(name string) Definition

Get returns a spinner definition by name, or the default if not found.

type Spinner

type Spinner struct {
	Name  string
	Style *style.Style
	Speed float64 // Multiplier for animation speed (1.0 = normal)
	// contains filtered or unexported fields
}

Spinner renders an animated spinner.

func New

func New(name string) *Spinner

New creates a new Spinner with the given name.

func (*Spinner) FrameCount

func (s *Spinner) FrameCount() int

FrameCount returns the number of frames in this spinner.

func (*Spinner) Interval

func (s *Spinner) Interval() float64

Interval returns the interval between frames.

func (*Spinner) Render

func (s *Spinner) Render(currentTime float64) []segment.Segment

Render renders the spinner at the given time.

func (*Spinner) Reset

func (s *Spinner) Reset()

Reset resets the spinner animation to the beginning.

func (*Spinner) WithSpeed

func (s *Spinner) WithSpeed(speed float64) *Spinner

WithSpeed sets the animation speed multiplier.

func (*Spinner) WithStyle

func (s *Spinner) WithStyle(st style.Style) *Spinner

WithStyle sets the spinner style.

Jump to

Keyboard shortcuts

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