ysmrr

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: MIT Imports: 12 Imported by: 41

README

You spin me right round

Ysmrr is a simple multi-line spinner package for your terminal.

Installing

go get -u github.com/chelnak/ysmrr

Usage

// Create a new spinner manager
sm := ysmrr.NewSpinnerManager()

// Add a spinner
mySpinner := sm.AddSpinner("Spinny things...")

// Start the spinners that have been added to the group
sm.Start()

// Set the spinner to complete
time.Sleep(2 * time.Second)
mySpinner.Complete()

// Stop the spinners in the group
time.Sleep(2 * time.Second)
sm.Stop()

For example usage, check out the examples directory for.

Inspiration

Ysmrr was inspired by the following projects:

It also uses github.com/fatih/color for the underlying color system.

Documentation

Overview

Package ysmrr provides a simple interface for creating and managing multiple spinners.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*spinnerManager)

Option represents a spinner manager option.

func WithCharMap

func WithCharMap(chars []string) Option

WithCharMap sets the characters used for the spinners. Available charmaps can be found in the package github.com/chelnak/ysmrr/pkg/charmap. The default charmap is the Dots.

func WithCompleteColor added in v0.0.5

func WithCompleteColor(c colors.Color) Option

WithCompleteColor sets the color of the complete icon. Available colors can be found in the package github.com/chelnak/ysmrr/pkg/colors. The default color is FgHiGreen.

func WithErrorColor added in v0.0.5

func WithErrorColor(c colors.Color) Option

WithErrorColor sets the color of the error icon. Available colors can be found in the package github.com/chelnak/ysmrr/pkg/colors. The default color is FgHiRed.

func WithFrameDuration

func WithFrameDuration(d time.Duration) Option

WithFrameDuration sets the duration of each frame. The default duration is 250 milliseconds.

func WithMessageColor added in v0.0.6

func WithMessageColor(c colors.Color) Option

WithMessageColor sets the color of the message. Available colors can be found in the package github.com/chelnak/ysmrr/pkg/colors. The default color is NoColor.

func WithSpinnerColor

func WithSpinnerColor(c colors.Color) Option

WithSpinnerColor sets the color of the spinners. Available colors can be found in the package github.com/chelnak/ysmrr/pkg/colors. The default color is FgHiGreen.

func WithWriter

func WithWriter(w io.Writer) Option

WithWriter sets the writer used for the spinners. The writer can be anything that implements the io.Writer interface. The default writer is os.Stdout.

type Spinner added in v0.0.5

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

Spinner manages a single spinner

func NewSpinner

func NewSpinner(options SpinnerOptions) *Spinner

NewSpinner creates a new spinner instance.

func (*Spinner) Complete added in v0.0.5

func (s *Spinner) Complete()

Complete marks the spinner as complete.

func (*Spinner) Error added in v0.0.5

func (s *Spinner) Error()

Error marks the spinner as error.

func (*Spinner) GetMessage added in v0.0.5

func (s *Spinner) GetMessage() string

GetMessage returns the current spinner message.

func (*Spinner) IsComplete added in v0.0.5

func (s *Spinner) IsComplete() bool

IsComplete returns true if the spinner is complete.

func (*Spinner) IsError added in v0.0.5

func (s *Spinner) IsError() bool

IsError returns true if the spinner is in error state.

func (*Spinner) Print added in v0.0.5

func (s *Spinner) Print(w io.Writer, char string)

Print prints the spinner at a given position.

func (*Spinner) UpdateMessage added in v0.0.5

func (s *Spinner) UpdateMessage(message string)

UpdateMessage updates the spinner message.

type SpinnerManager

type SpinnerManager interface {
	AddSpinner(msg string) *Spinner
	GetSpinners() []*Spinner
	GetWriter() io.Writer
	GetCharMap() []string
	GetFrameDuration() time.Duration
	GetSpinnerColor() colors.Color
	GetErrorColor() colors.Color
	GetCompleteColor() colors.Color
	GetMessageColor() colors.Color
	Start()
	Stop()
}

SpinnerManager manages spinners

func NewSpinnerManager

func NewSpinnerManager(options ...Option) SpinnerManager

NewSpinnerManager creates a new spinner manager.

type SpinnerOptions added in v0.0.5

type SpinnerOptions struct {
	SpinnerColor  colors.Color
	CompleteColor colors.Color
	ErrorColor    colors.Color
	MessageColor  colors.Color
	Message       string
}

Directories

Path Synopsis
examples
advanced command
basic command
pkg
charmap
Package charmap provides a collection of character maps to be used with a spinner.
Package charmap provides a collection of character maps to be used with a spinner.
colors
Package colors provides a collection of color definitions for use with a spinner.
Package colors provides a collection of color definitions for use with a spinner.
tput
Package tput provides convenience functions for sending escape sequences to the terminal.
Package tput provides convenience functions for sending escape sequences to the terminal.

Jump to

Keyboard shortcuts

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