spinner

package
v0.10.7 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Line = Spinner{
		Frames: []string{"|", "/", "-", "\\"},
		FPS:    time.Second / 10,
	}
	Dot = Spinner{
		Frames: []string{"⣾ ", "⣽ ", "⣻ ", "⢿ ", "⡿ ", "⣟ ", "⣯ ", "⣷ "},
		FPS:    time.Second / 10,
	}
	MiniDot = Spinner{
		Frames: []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"},
		FPS:    time.Second / 12,
	}
	Jump = Spinner{
		Frames: []string{"⢄", "⢂", "⢁", "⡁", "⡈", "⡐", "⡠"},
		FPS:    time.Second / 10,
	}
	Pulse = Spinner{
		Frames: []string{"█", "▓", "▒", "░"},
		FPS:    time.Second / 8,
	}
	Points = Spinner{
		Frames: []string{"∙∙∙", "●∙∙", "∙●∙", "∙∙●"},
		FPS:    time.Second / 7,
	}
	Globe = Spinner{
		Frames: []string{"🌍", "🌎", "🌏"},
		FPS:    time.Second / 4,
	}
	Moon = Spinner{
		Frames: []string{"🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘"},
		FPS:    time.Second / 8,
	}
	Monkey = Spinner{
		Frames: []string{"🙈", "🙉", "🙊"},
		FPS:    time.Second / 3,
	}
)

Some spinners to choose from. You could also make your own.

View Source
var NewModel = New

NewModel returns a model with default values.

Deprecated. Use New instead.

Functions

func Tick

func Tick() tea.Msg

Tick is the command used to advance the spinner one frame. Use this command to effectively start the spinner.

This method is deprecated. Use Model.Tick instead.

Types

type Model

type Model struct {

	// Spinner settings to use. See type Spinner.
	Spinner Spinner

	// Style sets the styling for the spinner. Most of the time you'll just
	// want foreground and background coloring, and potentially some padding.
	//
	// For an introduction to styling with Lip Gloss see:
	// https://github.com/charmbracelet/lipgloss
	Style lipgloss.Style

	// MinimumLifetime is the minimum amount of time the spinner can run. Any
	// logic around this can be implemented in view that implements this
	// spinner. If HideFor is set MinimumLifetime will be added on top of
	// HideFor. In other words, if HideFor is 100ms and MinimumLifetime is
	// 200ms then MinimumLifetime will expire after 300ms.
	//
	// MinimumLifetime is optional.
	//
	// This is considered experimental and may not appear in future versions of
	// this library.
	MinimumLifetime time.Duration

	// HideFor can be used to wait to show the spinner until a certain amount
	// of time has passed. This can be useful for preventing flicking when load
	// times are very fast.
	// Optional.
	//
	// This is considered experimental and may not appear in future versions of
	// this library.
	HideFor time.Duration
	// contains filtered or unexported fields
}

Model contains the state for the spinner. Use NewModel to create new models rather than using Model as a struct literal.

func New added in v0.10.5

func New() Model

New returns a model with default values.

func (*Model) Finish

func (m *Model) Finish()

Finish sets the internal timer to a completed state so long as the spinner isn't flagged to be showing. If it is showing, finish has no effect. The idea here is that you call Finish if your operation has completed and, if the spinner isn't showing yet (by virtue of HideFor) then Visible() doesn't show the spinner at all.

This is intended to work in conjunction with MinimumLifetime and MinimumStartTime, is completely optional.

This function is optional and generally considered for advanced use only. Most of the time your application logic will obviate the need for this method.

This is considered experimental and may not appear in future versions of this library.

func (Model) ID added in v0.10.5

func (m Model) ID() int

ID returns the spinner's unique ID.

func (*Model) Start

func (m *Model) Start()

Start resets resets the spinner start time. For use with MinimumLifetime and MinimumStartTime. Optional.

This function is optional and generally considered for advanced use only. Most of the time your application logic will obviate the need for this method.

This is considered experimental and may not appear in future versions of this library.

func (Model) Tick added in v0.10.5

func (m Model) Tick() tea.Msg

Tick is the command used to advance the spinner one frame. Use this command to effectively start the spinner.

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update is the Tea update function. This will advance the spinner one frame every time it's called, regardless the message passed, so be sure the logic is setup so as not to call this Update needlessly.

func (Model) View

func (m Model) View() string

View renders the model's view.

func (Model) Visible

func (m Model) Visible() bool

Visible returns whether or not the view should be rendered. Works in conjunction with Model.HideFor and Model.MinimumLifetimeReached. You should use this method directly to determine whether or not to render this view in the parent view and whether to continue sending spin messaging in the parent update function.

This function is optional and generally considered for advanced use only. Most of the time your application logic will obviate the need for this method.

This is considered experimental and may not appear in future versions of this library.

type Spinner

type Spinner struct {
	Frames []string
	FPS    time.Duration
}

Spinner is a set of frames used in animating the spinner.

type TickMsg

type TickMsg struct {
	Time time.Time

	ID int
	// contains filtered or unexported fields
}

TickMsg indicates that the timer has ticked and we should render a frame.

Jump to

Keyboard shortcuts

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