spinner

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 9 Imported by: 0

README ¶

🎡 Spinner

Check the example.

Documentation ¶

Overview ¶

Package spinner spins a small progress spinner on stderr while a long-running operation is running.

sp := spinner.Start("Spinning...")
defer sp.Stop()
work()

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func Spin ¶

func Spin(label string, f func(), opts ...Option)

Spin starts a spinner with a label, runs f, then stops the spinner.

Types ¶

type Option ¶

type Option func(*Spinner)

Option configures a Spinner.

func WithDelay ¶

func WithDelay(d time.Duration) Option

WithDelay sets the animation frame interval.

func WithFrames ¶

func WithFrames(frames []string) Option

WithFrames sets the animation frames.

func WithLabelFunc ¶

func WithLabelFunc(f func() string) Option

WithLabelFunc sets a function called on every animation tick to regenerate the label, and once more when Stop ends the animation, so the line left on screen shows the final state rather than the last frame's. The label passed to Start is still used for non-TTY output and the frame shown during startDelay. The func is called from the spinner's background goroutine, so it must be safe for concurrent use alongside any state it reads that the caller also mutates. Stop waits for that last call to return.

func WithMaxWidth ¶

func WithMaxWidth(n int) Option

WithMaxWidth sets the cap on the rendered line, in terminal cells.

func WithStartDelay ¶

func WithStartDelay(d time.Duration) Option

WithStartDelay sets how long to wait before the spinner appears. Zero shows it immediately; negative values are ignored.

type Spinner ¶

type Spinner struct {
	// contains filtered or unexported fields
}

Spinner animates a progress indicator on stderr.

func Start ¶

func Start(label string, opts ...Option) *Spinner

Start prints label and animates in place on stderr when stderr is a TTY. Call Stop when the operation finishes.

func (*Spinner) Stop ¶

func (s *Spinner) Stop()

Stop halts the spinner. On TTY output, the animation is erased and the label is left behind on its own line, regenerated once by WithLabelFunc if one is set. Stop blocks until the spinner has stopped writing, and is safe to call more than once. Calling it on a Spinner that Start did not return does nothing.

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

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