spinner

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 5 Imported by: 2

README

spinner is a go package for showing terminal spinners

Documentation

Index

Examples

Constants

View Source
const (
	Black  = "\033[38;5;0m"
	Green  = "\033[38;5;2m"
	Olive  = "\033[38;5;3m"
	Navy   = "\033[38;5;4m"
	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 Color256

func Color256(n int) string

func ColorPulse

func ColorPulse(start, end int, duration time.Duration) func() string

func GreyPulse

func GreyPulse(interval time.Duration) func() string

func SpeedupInterval added in v0.1.1

func SpeedupInterval(start, end, duration time.Duration) func() time.Duration

func WithColor

func WithColor(color string) func(*Spinner)

func WithColorFunc

func WithColorFunc(f func() string) func(*Spinner)

func WithHideCursor

func WithHideCursor(hide bool) func(*Spinner)

func WithIntervalFunc

func WithIntervalFunc(f func() time.Duration) func(*Spinner)

Types

type Option

type Option func(*Spinner)

func WithFrames

func WithFrames(frames []string) Option

func WithInterval

func WithInterval(d time.Duration) Option

func WithPosition added in v0.1.2

func WithPosition(pos int) Option

func WithWriter

func WithWriter(w io.Writer) Option

type Spinner

type Spinner struct {
	// contains filtered or unexported fields
}
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")
	}
}

func New

func New(opts ...Option) *Spinner

func (*Spinner) Start

func (s *Spinner) Start()

func (*Spinner) Stop

func (s *Spinner) Stop()

Jump to

Keyboard shortcuts

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