Documentation
¶
Overview ¶
Package spinner implements simple "progress spinner" for terminal output.
Spinner expects to have exclusive access to underlying *os.File, that nothing else is writing there while spinner is in use, otherwise output would be broken.
If provided *os.File (usually os.Stdout or os.Sterr) is not attached to a terminal, spinner outputs nothing, that makes it safe to redirect program output to files, pipes, etc.
Spinner can either be used manually, by first creating it with New function, then periodically calling Spin() method on it to refresh output and finally finishing with Clear() method call to clean output; or package-level Spin shortcut function can be used to launch background goroutine that handles output refresh.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Spin ¶
Spin is a shortcut function which creates new Spinner, launches background goroutine that periodically calls spinner's Spin method, and returns function that stops that background goroutine and clears spinner output.
Can be used like this:
func work() { defer spinner.Spin(os.Stderr, "working...")() // logic here }
It is expected that nothing else is writing to underlying *os.File until stop function returns.
Types ¶
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner implements terminal spinner attached to *os.File which usually either stdout or stderr. Both zero and nil values are valid and are no-op. If spinner created on an *os.File that is not attached to the terminal, spinner's methods do nothing.
Its methods are NOT thread safe, and it expects to have exclusive access to underlying *os.File — that nothing is writing to it while Spinner's methods are in use.
func New ¶
New returns new Spinner attached to f which usually either os.Stdout or os.Stderr. If f is attached to a terminal, retrurned spinner would output text followed by space and "spinning" character on each Spin call.
*os.File provided must not be nil.