gospinner

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2018 License: MIT Imports: 8 Imported by: 2

README

Gospinner GoDoc Build Status

Gospinner lets you make simple spinners for your go cli applications. Is fast and easy to use. Simple customizations and ready to go defaults!

gospinner

Install

go get github.com/slok/gospinner

Running examples

Examples

Default spinner
s, _ := gospinner.NewSpinner(gospinner.Dots)
s.Start("Loading")
// Do stuff
s.Finish()
Custom color spinner
s, _ := gospinner.NewSpinnerWithColor(gospinner.Ball, gospinner.FgGreen)
s.Start("Loading")
// Do stuff
s.Finish()
No color spinner
s, _ := s, _ := gospinner.NewSpinnerNoColor(gospinner.GrowHorizontal)
s.Start("Loading")
// Do stuff
s.Finish()
Spinner with finishers
s, _ := gospinner.NewSpinner(gospinner.Pong)

s.Start("Loading job 1")
// Do job 1 ...
s.Succeed()

s.Start("Loading job 2")
// Do job 2 ...
s.Fail()

s.Start("Loading job 3")
// Do job 3 ...
s.Warn()
Changing message while spinning and finishing with custom message
s, _ := gospinner.NewSpinner(gospinner.Square)
s.Start("Loading")
// Do stuff
s.SetMessage("Starting server dependencies")
// Do more stuff
s.SetMessage("Starting server")
// Do more stuff
s.FinishWithMessage("⚔", "Finished!")
Available spinners:
  • Ball
  • Column
  • Slash
  • Square
  • Triangle
  • Dots
  • Dots2
  • Pipe
  • SimpleDots
  • SimpleDotsScrolling
  • GrowVertical
  • GrowHorizontal
  • Arrow
  • BouncingBar
  • BouncingBall
  • Pong
  • ProgressBar

For more customizations you should check the documentation

Credits

Xabier Larrakoetxea

License

The MIT License (MIT) - see LICENSE.md for more details

Documentation

Overview

Package gospinner is a spinner package to create spinners in a fast, beatiful and easy way. No more ugly and old cli applications, give feedback to your users

Use the simplest spinner and start getting awsome cli applications:

s, _ := gospinner.NewSpinnerWithColor(gospinner.Ball, gospinner.FgGreen)
s.Start("Loading")
// Do stuff
s.Finish()

However sometimes you want custom colors for your spinners:

s, _ := s, _ := gospinner.NewSpinnerNoColor(gospinner.GrowHorizontal)
s.Start("Loading")
// Do stuff
s.Finish()

Easy right? but that finish line is a little bit sad, Lets use some cool finishers!

s, _ := gospinner.NewSpinner(gospinner.Pong)

s.Start("Loading job 1")
// Do job 1 ...
s.Succeed()

s.Start("Loading job 2")
// Do job 2 ...
s.Fail()

s.Start("Loading job 3")
// Do job 3 ...
s.Warn()

You have more stuff to customize it, check it on the documentation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Animation

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

Animation represents an animation with frames and speed (recommended)

type AnimationKind

type AnimationKind int

AnimationKind represents the kind of the animation

const (
	Ball AnimationKind = iota
	Column
	Slash
	Square
	Triangle
	Dots
	Dots2
	Pipe
	SimpleDots
	SimpleDotsScrolling
	GrowVertical
	GrowHorizontal
	Arrow
	BouncingBar
	BouncingBall
	Pong
	ProgressBar
)

type Color

type Color struct {
	*color.Color
}

Color is and addaptation of fatih color as own type for easy usage for the lib users

type ColorAttr

type ColorAttr color.Attribute

ColorAttr is an adaptation of fatih color attributes as own type for easy usage for the lib users

const (
	FgBlack ColorAttr = iota + 30
	FgRed
	FgGreen
	FgYellow
	FgBlue
	FgMagenta
	FgCyan
	FgWhite
)
const (
	FgHiBlack ColorAttr = iota + 90
	FgHiRed
	FgHiGreen
	FgHiYellow
	FgHiBlue
	FgHiMagenta
	FgHiCyan
	FgHiWhite
)

type Spinner

type Spinner struct {

	// Writer will be the target of the printing
	Writer io.Writer

	// Our locker
	sync.Mutex
	// contains filtered or unexported fields
}

Spinner is a representation of the animation itself

func NewSpinner

func NewSpinner(kind AnimationKind) (*Spinner, error)

NewSpinner creates a new spinner with the common default values, this should be the most used one, fast and easy.

func NewSpinnerNoColor

func NewSpinnerNoColor(kind AnimationKind) (*Spinner, error)

NewSpinnerNoColor creates an spinner that doesn't have color, shoud be compatible with all the terminals

func NewSpinnerWithColor

func NewSpinnerWithColor(kind AnimationKind, color ColorAttr) (*Spinner, error)

NewSpinnerWithColor creates an spinner with a custom color, same as the default one, but instead you can select the color you want for the spinner

func (*Spinner) Fail

func (s *Spinner) Fail() error

Fail will stop the animation with a failure symbol where the spinner is

func (*Spinner) Finish

func (s *Spinner) Finish() error

Finish will stop an write to the next line

func (*Spinner) FinishWithMessage

func (s *Spinner) FinishWithMessage(symbol, closingMessage string) error

FinishWithMessage will finish animation setting a message and a symbol where the spinner was

func (*Spinner) FinishWithSymbol

func (s *Spinner) FinishWithSymbol(symbol string) error

FinishWithSymbol will finish the animation with a symbol where the spinner is

func (*Spinner) Render

func (s *Spinner) Render() error

Render will render manually an step

func (*Spinner) Reset

func (s *Spinner) Reset()

Reset will set the spinner to its initial frame

func (*Spinner) SetMessage

func (s *Spinner) SetMessage(message string)

SetMessage will set new message on the animation without stoping it

func (*Spinner) Start

func (s *Spinner) Start(message string) error

Start will animate with the recommended speed, this should be the default choice.

func (*Spinner) StartWithSpeed

func (s *Spinner) StartWithSpeed(message string, speed time.Duration) error

StartWithSpeed will start animation witha custom speed for the spinner

func (*Spinner) Stop

func (s *Spinner) Stop() error

Stop will stop the animation

func (*Spinner) Succeed

func (s *Spinner) Succeed() error

Succeed will stop the animation with a success symbol where the spinner is

func (*Spinner) Warn

func (s *Spinner) Warn() error

Warn will stop the animation with a warning symbol where the spinner is

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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