spinner

package module
v0.0.0-...-092535a Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

README

Simple CLI Spinner for Go

This is a simple spinner / activity indicator for Go command line apps. Useful when you want your users to know that there is activity and that the program isn't hung.
The indicator automagically converts itself in a simple log message if it detects that you have piped stdout to somewhere else than the console (You don't really want a spinner in your logger, do you?).

asciicast

Installation

To install spinner.go, simply run:

$ go get github.com/janeczku/go-spinner

Make sure your PATH includes to the $GOPATH/bin directory so your commands can be easily used:

export PATH=$PATH:$GOPATH/bin

Example usage

package main

import (
	"time"
	"github.com/janeczku/go-spinner"
	
)

func main() {
	s := spinner.StartNew("This may take some while...")
	time.Sleep(3 * time.Second) // something more productive here
	s.Stop()
}

API

s := spinner.StartNew(title string)

Quickstart. Creates a new spinner with default options and start it

s := spinner.NewSpinner(title string)

Creates a new spinner object

s.SetSpeed(time.Millisecond)

Sets a custom speed for the spinner animation (default 150ms/frame)

s.SetCharset([]string)

If you don't like the spinning stick, give it an Array of strings like {".", "o", "0", "@", "*"}

s.Start()

Start printing out the spinner animation

s.Stop()

Stops the spinner

Documentation

Index

Constants

View Source
const (
	// 150ms per frame
	DEFAULT_FRAME_RATE = time.Millisecond * 150
)

Variables

View Source
var DefaultCharset = []string{"|", "/", "-", "\\"}

Functions

This section is empty.

Types

type Spinner

type Spinner struct {
	sync.Mutex
	Title     string
	Charset   []string
	FrameRate time.Duration

	Output io.Writer
	NoTty  bool
	// contains filtered or unexported fields
}

func NewSpinner

func NewSpinner(title string) *Spinner

create spinner object

func StartNew

func StartNew(title string) *Spinner

start a new spinner, title can be an empty string

func (*Spinner) SetCharset

func (sp *Spinner) SetCharset(chars []string) *Spinner

set custom spinner character set

func (*Spinner) SetSpeed

func (sp *Spinner) SetSpeed(rate time.Duration) *Spinner

set custom spinner frame rate

func (*Spinner) Start

func (sp *Spinner) Start() *Spinner

start spinner

func (*Spinner) Stop

func (sp *Spinner) Stop()

stop and clear the spinner

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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