spinner

package module
Version: v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2019 License: MIT Imports: 4 Imported by: 0

README

Spinner

CircleCI

A simple spinner for CLI UIs, building upon the spinner outlined in 'The Go Programming Language' book, and some ideas from Brian Downs' Spinner, mainly around testing and erasing spinner output.

Image of Spinner example

It's a very minimalist implementation with a single spinner 'style', and an API consisting of Start() and Stop() methods:

// Creates a default spinner, outputting to os.Stdout
s := spinner.New()
s.Start()
// Do some intensive stuff
s.Stop()

An optional prefix can be output by the Spinner by passing in an option function in the call to spinner.New():

s := spinner.New(spinner.Prefix("foo"))
s.Start()
// ...
s.Stop()

The spinner structure contains an io.Writer; in the default implementation this is just os.Stdout, but this can be replaced with something else if required (as is the case for the tests); use the spinner.Writer() option function when calling spinner.New() to override the default writer.

Documentation

Overview

Package spinner is a simple implementation of a text-based 'spinner' UI widget, for use when programs need to indicate they are busy. It takes inspiration from Brian Down's spinner implementation (the erase() method in particular, and embedding an io.Writer for testing), and the simple spinner implementation in 'The Go Programming Lanuguage'

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Prefix

func Prefix(prefix string) option

Prefix sets the prefix value of the spinner.

func Writer

func Writer(w io.Writer) option

Writer sets the io.Writer of the spinner.

Types

type Spinner

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

Spinner holds all the required options for the spinner instance; users can supply a prefix if required (otherwise the spinner will just display as-is) and io.Writer.

func New

func New(opts ...option) *Spinner

New returns an initialised Spinner structure; callers will need to supply a prefix to the spinner if required.

The default behaviour outputs to stdout; this can be overridden by passing in the Writer() config option with an appropriate implementation of io.Writer.

func (*Spinner) Start

func (s *Spinner) Start()

Start initiates the spinner

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner, and erases all emitted characters

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL