spinner

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Interval is how often the spinner updates. This controls the speed of the spinner.
	// The default value is 100ms.
	Interval time.Duration
	// Out is where the spinner is written. The default value is os.Stderr.
	Out io.Writer
	// Message is the text written after the spinner.
	Message string
	// Count is the total amount of items to track the progress of.
	Count int
	// MaxMessageLength is the max length of the message that is written. If the message is
	// longer then this length it will be truncated. The default max length is 80.
	MaxMessageLength int
	// PersistMessages is whether or not messages should be persisted to Out when the message
	// is updated. By default messages are not persisted and are replaced.
	PersistMessages bool
}

Options allows for customization of a spinner.

type Spinner

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

Spinner represents the state of the spinner.

func New

func New(opts Options) *Spinner

New creates a new spinner instance using the given options.

func (*Spinner) Inc

func (s *Spinner) Inc()

Inc increments the progress of the spinner. If the spinner has already reached full progress, Inc does nothing.

func (*Spinner) Start

func (s *Spinner) Start()

Start will start the spinner.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner if it is currently running.

func (*Spinner) UpdateMessage

func (s *Spinner) UpdateMessage(m string)

UpdateMessage changes the current message being shown by the spinner.

func (*Spinner) Write

func (s *Spinner) Write(p []byte) (int, error)

Write writes p to the spinner's writer after the current frame has been erased. Write will always immediately return successfully as p is first written to an internal buffer. The actual writing of the data to the spinner's writer will not occur until the appropriate time during the spinner animation.

Write will add a newline to the end of p in order to ensure that it does not interfere with the spinner animation.

type TTYOptions

type TTYOptions struct {
	Options
	IsaTTY bool
}

type TTYSpinner

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

TTYSpinner is a wrapper over a spinner that handles whether or not the spinner's output is a tty. If out is a tty, it functions the same as a Spinner. If out is not a tty, then the spinner will simply write messages to it without the spinner animation.

func NewTTY

func NewTTY(opts TTYOptions) *TTYSpinner

NewTTY creates a new TTYSpinner instance.

func (*TTYSpinner) Start

func (s *TTYSpinner) Start()

Start starts the spinner if out is a tty, otherwise it writes the message to out directly.

func (*TTYSpinner) UpdateMessage

func (s *TTYSpinner) UpdateMessage(m string)

UpdateMessage either updates the spinner message, or writes m directy to out depending on whether or not out is a tty.

func (*TTYSpinner) Write

func (s *TTYSpinner) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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