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 ¶
Types ¶
type Option ¶
type Option func(*Spinner)
Option configures a Spinner.
func WithLabelFunc ¶
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 ¶
WithMaxWidth sets the cap on the rendered line, in terminal cells.
func WithStartDelay ¶
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 ¶
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.