clispin

package module
v0.0.0-...-9e43aa1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2017 License: MIT Imports: 5 Imported by: 0

README

Travis status Godoc

clispin

Clispin is a Go library, that makes it ridiculously easy to integrate fancy unicode spinners in your app.

Usage

spinner := clispin.New(nil)
spinner.Start(func() {
    // Do your work here. Update spinner text with Print or Printf
    spinner.Printf("Downloading file %d/2", 1)
    time.Sleep(time.Second)
    spinner.Printf("Downloading file %d/2", 2)
    time.Sleep(time.Second)

    spinner.Print("Processing files")
    time.Sleep(time.Second)
    spinner.Print("Done")
})

clispin.New() creates a new spinner. You can pass in a Sprite struct to customize the spinner animation. If no sprite is provided, a default one is chosen.

There are also a couple of sprites included in this library.

Documentation

Index

Constants

View Source
const (
	ColorNone    = -1
	ColorBlack   = Color(color.FgBlack)
	ColorRed     = Color(color.FgRed)
	ColorGreen   = Color(color.FgGreen)
	ColorYellow  = Color(color.FgYellow)
	ColorBlue    = Color(color.FgBlue)
	ColorMagenta = Color(color.FgMagenta)
	ColorCyan    = Color(color.FgCyan)
	ColorWhite   = Color(color.FgWhite)
)

Variables

View Source
var SpriteFrames = map[int][]string{
	0:  {"←", "↖", "↑", "↗", "→", "↘", "↓", "↙"},
	1:  {"←", "↑", "→", "↓"},
	2:  {"⇐", "⇖", "⇑", "⇗", "⇒", "⇘", "⇓", "⇙"},
	3:  {"◢", "◣", "◤", "◥"},
	4:  {"◰", "◳", "◲", "◱"},
	5:  {"◴", "◷", "◶", "◵"},
	6:  {"◐", "◓", "◑", "◒"},
	7:  {"⬒", "⬔", "⬓", "⬕"},
	8:  {"⬖", "⬘", "⬗", "⬙"},
	9:  {"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"},
	10: {"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"},
}

SpriteFrames are a premade sets of sprite frames.

Functions

This section is empty.

Types

type Color

type Color int

type Spinner

type Spinner struct {
	RefreshInterval time.Duration
	LastFrame       string
	// contains filtered or unexported fields
}

Spinner is an infinite ui spinner with status text

func New

func New(sprite *Sprite) *Spinner

New creates a new Spinner with the given sprite. If sprite nil, a defualt sprite will be used.

func (*Spinner) Color

func (s *Spinner) Color(c Color)

Color sets the color for the spinner sprite

func (*Spinner) Print

func (s *Spinner) Print(text string)

Print updates the status text of the spinner

func (*Spinner) Printf

func (s *Spinner) Printf(format string, p ...interface{})

Printf updates the status text of the spinner

func (*Spinner) Start

func (s *Spinner) Start(f func())

Start starts the spinner while executing the provided function. This functions blocks until the end of the supplied function. The rendering of the spinner + text is done on a different goroutine. The user function will be executed on the main thread.

type Sprite

type Sprite struct {
	Interval int64
	// contains filtered or unexported fields
}

Sprite is a unicode sprite implementation.

func NewSprite

func NewSprite(frames []string) *Sprite

NewSprite creates a new sprite given the specified frames. TODO: add update interval param

func (*Sprite) Frame

func (s *Sprite) Frame() string

Frame returns the current frame

func (*Sprite) Update

func (s *Sprite) Update() bool

Update updates the animation. If the function returns true the current frame changed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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