Documentation
¶
Overview ¶
Package components provides interactive UI components for the Skills CLI.
Package components provides interactive UI components for the Skills CLI.
Index ¶
- func Confirm(message string, defaultYes bool) (bool, error)
- func ConfirmWithIO(message string, defaultYes bool, in io.Reader, out io.Writer) (bool, error)
- func Input(prompt string) (string, error)
- func InputWithDefault(prompt, defaultValue string) (string, error)
- func InputWithIO(prompt, placeholder, defaultValue string, in io.Reader, out io.Writer) (string, error)
- func InputWithPlaceholder(prompt, placeholder string) (string, error)
- func Password(prompt string) (string, error)
- func PasswordWithIO(prompt string, in io.Reader, out io.Writer) (string, error)
- func RunStatus[T any](out io.Writer, message string, fn func() (T, error)) (T, error)
- func RunWithSpinner[T any](message string, fn func() (T, error)) (T, error)
- func RunWithSpinnerOutput[T any](message string, out io.Writer, fn func() (T, error)) (T, error)
- type IOContext
- func (ioc *IOContext) Confirm(message string, defaultYes bool) (bool, error)
- func (ioc *IOContext) Input(prompt, defaultValue string) (string, error)
- func (ioc *IOContext) InputWithPlaceholder(prompt, placeholder string) (string, error)
- func (ioc *IOContext) Select(title string, options []Option) (*Option, error)
- func (ioc *IOContext) SelectWithDefault(title string, options []Option, defaultIndex int) (*Option, error)
- type MultiProgress
- type MultiSelectOption
- type Option
- func Select(title string, options []Option) (*Option, error)
- func SelectWithDefault(title string, options []Option, defaultIndex int) (*Option, error)
- func SelectWithDefaultAndIO(title string, options []Option, defaultIndex int, in io.Reader, out io.Writer) (*Option, error)
- func SelectWithIO(title string, options []Option, in io.Reader, out io.Writer) (*Option, error)
- type ProgressBar
- type ProgressBarOption
- type Spinner
- type Status
- type StatusLine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Confirm ¶
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 ¶
ConfirmWithIO displays an interactive confirmation prompt using custom IO.
func Input ¶
Input displays an interactive text input prompt. Falls back to simple readline for non-TTY environments.
func InputWithDefault ¶
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 ¶
InputWithPlaceholder displays an interactive text input with placeholder text.
func PasswordWithIO ¶
PasswordWithIO displays a password input using custom IO.
func RunStatus ¶
RunStatus runs a function while showing a status spinner. Shows a success/fail message based on the result.
func RunWithSpinner ¶
RunWithSpinner runs a function while showing a spinner. Returns the function's result and any error.
Types ¶
type IOContext ¶
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 ¶
NewIOContext creates a new IO context
func (*IOContext) InputWithPlaceholder ¶
InputWithPlaceholder prompts for text input with placeholder text
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 ¶ added in v0.5.4
MultiSelectOption represents a selectable option with a checked state.
func MultiSelect ¶ added in v0.5.4
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 ¶ added in v0.5.4
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 ¶
Option represents a selectable option.
func Select ¶
Select displays an interactive selection menu and returns the selected option. Falls back to numbered menu input for non-TTY environments.
func SelectWithDefault ¶
SelectWithDefault selects with a default option highlighted.
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) 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.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner displays a spinner with a message. The spinner runs until Stop() is called on the returned Spinner.
func NewSpinner ¶
NewSpinner creates a new spinner with the given message.
func NewSpinnerWithOutput ¶
NewSpinnerWithOutput creates a new spinner with custom output.
func (*Spinner) Stop ¶
func (s *Spinner) Stop()
Stop stops the spinner and optionally shows a result message.
func (*Spinner) StopWithError ¶
StopWithError stops the spinner and records an error.
func (*Spinner) UpdateMessage ¶
UpdateMessage sends a message update to the spinner.
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.
func (*Status) Clear ¶
func (s *Status) Clear()
Clear clears the status line without showing a final message.
func (*Status) Done ¶
Done completes the status with an optional final message. If finalMessage is empty, the status line is cleared.
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) Done ¶
func (s *StatusLine) Done(message string)
Done clears the line and optionally prints a final message on a new line.
func (*StatusLine) SetSilent ¶
func (s *StatusLine) SetSilent(silent bool)
SetSilent enables silent mode.