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 ¶
const DefaultDoneGlyph = "✓"
DefaultDoneGlyph is the check mark printed by Done when Options.DoneGlyph is empty.
const DefaultDoneMessage = "ready"
DefaultDoneMessage is the settle text used when Options.DoneMessage is empty.
const DefaultInterval = time.Second / 12
DefaultInterval is the frame interval used when Options.Interval is unset.
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 ¶
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.