components

package
v2.3.8 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package components provides interactive UI components for the Skills CLI.

Package components provides interactive UI components for the Skills CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Confirm

func Confirm(message string, defaultYes bool) (bool, error)

Confirm displays an interactive confirmation prompt. Returns true for yes, false for no. Falls back to Y/n prompt for non-TTY environments.

func ConfirmWithIO

func ConfirmWithIO(message string, defaultYes bool, in io.Reader, out io.Writer) (bool, error)

ConfirmWithIO displays an interactive confirmation prompt using custom IO.

func Input

func Input(prompt string) (string, error)

Input displays an interactive text input prompt. Falls back to simple readline for non-TTY environments.

func InputWithDefault

func InputWithDefault(prompt, defaultValue string) (string, error)

InputWithDefault displays an interactive text input with a default value.

func InputWithIO

func InputWithIO(prompt, placeholder, defaultValue string, in io.Reader, out io.Writer) (string, error)

InputWithIO displays an interactive text input using custom IO.

func InputWithPlaceholder

func InputWithPlaceholder(prompt, placeholder string) (string, error)

InputWithPlaceholder displays an interactive text input with placeholder text.

func Password

func Password(prompt string) (string, error)

Password displays a password input (masked characters).

func PasswordWithIO

func PasswordWithIO(prompt string, in io.Reader, out io.Writer) (string, error)

PasswordWithIO displays a password input using custom IO.

func RunStatus

func RunStatus[T any](out io.Writer, message string, fn func() (T, error)) (result T, err error)

RunStatus runs a function while showing a status spinner. The status line is cleared when the function completes; teardown also runs if fn panics.

func RunWithSpinner

func RunWithSpinner[T any](message string, fn func() (T, error)) (T, error)

RunWithSpinner runs a function while showing a spinner. Returns the function's result and any error.

func RunWithSpinnerOutput

func RunWithSpinnerOutput[T any](message string, out io.Writer, fn func() (T, error)) (result T, err error)

RunWithSpinnerOutput runs a function while showing a spinner on custom output. The spinner is torn down even if fn panics.

Types

type IOContext

type IOContext struct {
	In  io.Reader
	Out io.Writer
}

IOContext holds IO streams and provides convenient methods for interactive components This avoids passing io.Reader and io.Writer to every component call

func NewIOContext

func NewIOContext(in io.Reader, out io.Writer) *IOContext

NewIOContext creates a new IO context

func (*IOContext) Confirm

func (ioc *IOContext) Confirm(message string, defaultYes bool) (bool, error)

Confirm asks a yes/no question with a default answer

func (*IOContext) Input

func (ioc *IOContext) Input(prompt, defaultValue string) (string, error)

Input prompts for text input with optional default value

func (*IOContext) InputWithPlaceholder

func (ioc *IOContext) InputWithPlaceholder(prompt, placeholder string) (string, error)

InputWithPlaceholder prompts for text input with placeholder text

func (*IOContext) MultiSelect

func (ioc *IOContext) MultiSelect(title string, options []MultiSelectOption) ([]MultiSelectOption, error)

MultiSelect displays an interactive multi-selection menu and returns the chosen options (those with Selected=true in the result).

func (*IOContext) Select

func (ioc *IOContext) Select(title string, options []Option) (*Option, error)

Select displays an interactive selection menu

func (*IOContext) SelectWithDefault

func (ioc *IOContext) SelectWithDefault(title string, options []Option, defaultIndex int) (*Option, error)

SelectWithDefault displays a selection menu with a default option

type MultiProgress

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

MultiProgress manages multiple progress bars for concurrent downloads.

func NewMultiProgress

func NewMultiProgress(out io.Writer) *MultiProgress

NewMultiProgress creates a manager for multiple progress items.

func (*MultiProgress) Complete

func (mp *MultiProgress) Complete(id string)

Complete marks an item as complete.

func (*MultiProgress) Fail

func (mp *MultiProgress) Fail(id string, err error)

Fail marks an item as failed.

func (*MultiProgress) SetTotal

func (mp *MultiProgress) SetTotal(total int)

SetTotal sets the total number of items.

func (*MultiProgress) Start

func (mp *MultiProgress) Start(id, description string)

Start marks an item as started.

func (*MultiProgress) Update

func (mp *MultiProgress) Update(id string, percent float64)

Update updates an item's progress.

type MultiSelectOption

type MultiSelectOption struct {
	Label       string
	Value       string
	Description string
	Selected    bool
}

MultiSelectOption represents a selectable option with a checked state.

func MultiSelect

func MultiSelect(title string, options []MultiSelectOption) ([]MultiSelectOption, error)

MultiSelect displays an interactive multi-selection menu and returns the selected options. Falls back to numbered menu input for non-TTY environments.

func MultiSelectWithIO

func MultiSelectWithIO(title string, options []MultiSelectOption, in io.Reader, out io.Writer) ([]MultiSelectOption, error)

MultiSelectWithIO displays an interactive multi-selection menu using custom IO.

type Option

type Option struct {
	Label       string
	Value       string
	Description string
}

Option represents a selectable option.

func Select

func Select(title string, options []Option) (*Option, error)

Select displays an interactive selection menu and returns the selected option. Falls back to numbered menu input for non-TTY environments.

func SelectWithDefault

func SelectWithDefault(title string, options []Option, defaultIndex int) (*Option, error)

SelectWithDefault selects with a default option highlighted.

func SelectWithDefaultAndIO

func SelectWithDefaultAndIO(title string, options []Option, defaultIndex int, in io.Reader, out io.Writer) (*Option, error)

SelectWithDefaultAndIO selects with a default option highlighted using custom IO.

func SelectWithIO

func SelectWithIO(title string, options []Option, in io.Reader, out io.Writer) (*Option, error)

SelectWithIO displays an interactive selection menu using custom IO.

type ProgressBar

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

ProgressBar represents an interactive progress bar.

func NewProgressBar

func NewProgressBar(description string, opts ...ProgressBarOption) *ProgressBar

NewProgressBar creates a new progress bar.

func NewProgressBarWithOutput

func NewProgressBarWithOutput(description string, out io.Writer, opts ...ProgressBarOption) *ProgressBar

NewProgressBarWithOutput creates a new progress bar with custom output.

func (*ProgressBar) Done

func (p *ProgressBar) Done()

Done completes the progress bar.

func (*ProgressBar) Start

func (p *ProgressBar) Start()

Start begins the progress bar.

func (*ProgressBar) Update

func (p *ProgressBar) Update(percent float64)

Update updates the progress bar to the given percentage (0.0 to 1.0).

func (*ProgressBar) UpdateWithDescription

func (p *ProgressBar) UpdateWithDescription(percent float64, description string)

UpdateWithDescription updates both progress and description.

type ProgressBarOption

type ProgressBarOption func(*ProgressBar)

ProgressBarOption configures a progress bar.

func WithWidth

func WithWidth(width int) ProgressBarOption

WithWidth sets the progress bar width.

type Spinner

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

Spinner displays an animated spinner with a message until stopped.

Built on Status (plain in-place ANSI) rather than a bubbletea program: bubbletea queries terminal capabilities at startup, and a short-lived spinner exits before the terminal replies, leaking the reply bytes to the user's terminal (SK-763). Delegating also removes the old implementation's unsynchronized result read when the program quit while the wrapped function was still running.

func NewSpinner

func NewSpinner(message string) *Spinner

NewSpinner creates a new spinner with the given message.

func NewSpinnerWithOutput

func NewSpinnerWithOutput(message string, out io.Writer) *Spinner

NewSpinnerWithOutput creates a new spinner with custom output.

func (*Spinner) Start

func (s *Spinner) Start()

Start begins the spinner animation.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner and clears the line.

func (*Spinner) StopWithError

func (s *Spinner) StopWithError(_ error)

StopWithError stops the spinner and clears the line. The error is the caller's to report; the spinner line itself carries no final message.

func (*Spinner) UpdateMessage

func (s *Spinner) UpdateMessage(message string)

UpdateMessage updates the spinner message (for long-running operations).

type Status

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

Status provides a transient status line that updates in place. Use for operations where you want to show progress without cluttering output.

Rendered with plain ANSI writes rather than a bubbletea program: bubbletea queries the terminal for capabilities at startup, and for a short-lived status the replies arrive after the program has exited and restored echo, so they end up printed to the user's terminal as garbage (SK-763).

func NewStatus

func NewStatus(out io.Writer) *Status

NewStatus creates a new status line.

func (*Status) Clear

func (s *Status) Clear()

Clear clears the status line without showing a final message.

func (*Status) Done

func (s *Status) Done(finalMessage string)

Done completes the status with an optional final message. If finalMessage is empty, the status line is cleared.

func (*Status) Fail

func (s *Status) Fail(message string)

Fail completes the status with an error message.

func (*Status) SetSilent

func (s *Status) SetSilent(silent bool)

SetSilent enables silent mode (no output).

func (*Status) Start

func (s *Status) Start(message string)

Start begins showing a status with spinner.

func (*Status) Update

func (s *Status) Update(message string)

Update changes the status message.

type StatusLine

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

StatusLine is a simpler non-animated status that updates in place. Better for rapid updates where animation would be distracting.

func NewStatusLine

func NewStatusLine(out io.Writer) *StatusLine

NewStatusLine creates a simple status line that updates in place.

func (*StatusLine) Clear

func (s *StatusLine) Clear()

Clear clears the status line.

func (*StatusLine) Done

func (s *StatusLine) Done(message string)

Done clears the line and optionally prints a final message on a new line.

func (*StatusLine) Set

func (s *StatusLine) Set(message string)

Set updates the status line text.

func (*StatusLine) SetSilent

func (s *StatusLine) SetSilent(silent bool)

SetSilent enables silent mode.

Jump to

Keyboard shortcuts

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