spinner

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: LGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, msg string, fn func(context.Context) error, opts ...Options) error

Run shows a spinner labeled msg while fn runs, then stops it — the convenience wrapper over Start/Complete for a blocking op that otherwise prints nothing (Docker build, cluster bring-up). fn gets a context that is cancelled if the user interrupts (Ctrl-C); on that cancellation Run returns a silent error so the terminal isn't flooded with a stack trace.

Types

type LogMsg

type LogMsg string

type Options

type Options struct {
	// Elapsed enables a "(Ns)" suffix that ticks once per Bubble Tea frame.
	// Use for silent long-running ops (cluster bring-up, image import) where
	// users would otherwise wonder if the process is hung.
	Elapsed bool
}

Options controls optional spinner behavior. Zero value is the legacy "spinner + text, no elapsed counter" mode used by the rest of the CLI.

type Session

type Session interface {
	Update(text string)
	Complete()
	Quit()
}

Session represents a running spinner session. Update changes the displayed text. Complete stops the spinner. Quit is an alias for Complete.

func Start

func Start(
	cancel context.CancelFunc,
	initialText string,
	opts ...Options,
) (Session, error)

Start creates, runs, and returns a spinner session. The variadic opts is optional — pass at most one Options value to enable elapsed-time display or other modes.

type Spinner

type Spinner struct {
	Spinner spinner.Model
	Cancel  func()

	// Started is the moment the spinner began; used to render an elapsed
	// counter "(Ns)" when ShowElapsed is true. Bubble Tea re-renders on
	// every Spinner.Tick (~100ms) so the counter updates without us
	// scheduling our own ticks.
	Started     time.Time
	ShowElapsed bool
	// contains filtered or unexported fields
}

Spinner is a component that displays a spinner while updating the logs.

func (*Spinner) Init

func (s *Spinner) Init() tea.Cmd

Init is called when the program starts and returns the initial command.

func (*Spinner) SetText

func (s *Spinner) SetText(text string)

func (*Spinner) Update

func (s *Spinner) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles incoming messages.

func (*Spinner) View

func (s *Spinner) View() string

View renders the UI.

Jump to

Keyboard shortcuts

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