spin

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package spin renders a single-line CLI spinner directly to a writer. It is a plain io.Writer animation with no bubbletea program behind it, so it suits startup work that happens before (or entirely outside of) a TUI.

Index

Constants

View Source
const DefaultDoneGlyph = "✓"

DefaultDoneGlyph is the check mark printed by Done when Options.DoneGlyph is empty.

View Source
const DefaultDoneMessage = "ready"

DefaultDoneMessage is the settle text used when Options.DoneMessage is empty.

View Source
const DefaultInterval = time.Second / 12

DefaultInterval is the frame interval used when Options.Interval is unset.

View Source
const DefaultMessage = "starting…"

DefaultMessage is the in-progress text used when Options.Message is empty.

Variables

This section is empty.

Functions

func DefaultFrames

func DefaultFrames() []string

DefaultFrames returns a copy of the frame set used when Options.Frames is empty.

Types

type Options

type Options struct {
	// Writer receives the animation. Defaults to os.Stderr.
	Writer io.Writer
	// Prefix is rendered dimmed ahead of the frame, e.g. "myapp ▸". When
	// empty no prefix (and no leading space) is written.
	Prefix string
	// Message is the dimmed in-progress text. Defaults to DefaultMessage.
	Message string
	// DoneMessage is the dimmed text Done settles on. Defaults to
	// DefaultDoneMessage.
	DoneMessage string
	// DoneGlyph is the check mark Done prints. Defaults to DefaultDoneGlyph.
	DoneGlyph string
	// Interval is the time between frames. Defaults to DefaultInterval.
	Interval time.Duration
	// Frames is the animation cycle. Defaults to DefaultFrames.
	Frames []string
	// Force animates even when Writer is not a terminal. Without it a
	// non-terminal Writer makes the Spinner a silent no-op.
	Force bool
}

Options configures a Spinner. The zero value is usable: it animates DefaultMessage on os.Stderr whenever that is a terminal.

type Spinner

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

Spinner is a running single-line animation. Create one with Start and end it with Stop or Done; every method is safe on a nil receiver.

func Start

func Start(opts Options) *Spinner

Start paints the first frame and animates until Stop or Done. When the writer is not a terminal and Force is unset it returns an inert Spinner that writes nothing.

func (*Spinner) Done

func (s *Spinner) Done()

Done ends the animation and replaces the line with a settled check mark and the done message, followed by a newline. Calls after the first are no-ops.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop ends the animation and erases the line. Calls after the first are no-ops.

Jump to

Keyboard shortcuts

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