Documentation
¶
Overview ¶
Package ui provides reusable interactive terminal UI components, standardized theming, and wrappers around the "charmbracelet/huh" and "charmbracelet/bubbles" libraries.
This package centralizes all interactive CLI components ensuring a consistent user experience and visual identity across the entire eng CLI application. It abstract away the complexity of managing terminal prompts and concurrent spinners.
Available Features ¶
- **Theming**: The `theme.EngTheme()` function supplies a consistent, adaptive light/dark mode HSL color palette across all interactive prompts.
- **Prompts**: Standardized functions for user interaction:
- `Confirm(message string, defaultVal bool)`: Yes/No prompts.
- `Input(message string, defaultVal string)`: Text input.
- `Select(message string, options []string, defaultVal string)`: Single selection.
- `MultiSelect(message string, options []string)`: Multiple selection.
- `Password(message string)`: Secret text input.
- **Spinners**: Beautiful and thread-safe progress spinners.
- `Spinner`: Single operation status and progress.
- `MultiSpinner`: For displaying multiple concurrent operations (e.g., parallel git pulls, downloading files, system updates).
Testing ¶
The prompt functions within this package are exposed as variables (e.g., `var Confirm = ConfirmImpl`) to allow them to be easily mocked during unit testing.
Index ¶
- Variables
- func ConfirmImpl(message string, defaultVal bool) (bool, error)
- func InputImpl(message, defaultVal string) (string, error)
- func MultiSelectImpl(message string, options, defaultSelected []string) ([]string, error)
- func PasswordImpl(message string) (string, error)
- func SelectImpl(message string, options []string, defaultVal string) (string, error)
- type MultiSpinner
- type ProgressSpinner
- type Spinner
Constants ¶
This section is empty.
Variables ¶
var ( Confirm = ConfirmImpl Input = InputImpl Select = SelectImpl MultiSelect = MultiSelectImpl Password = PasswordImpl )
Wrapper functions for testing.
var DisableProgress = false
DisableProgress can be set to true in tests to prevent pterm goroutines from spawning and causing race conditions.
var Out io.Writer = os.Stderr
Out is the writer used for spinner output. Tests may replace it.
Functions ¶
func ConfirmImpl ¶ added in v1.14.0
ConfirmImpl prompts the user with a yes/no question using the default theme.
func InputImpl ¶ added in v1.14.0
InputImpl prompts the user for text input using the default theme.
func MultiSelectImpl ¶ added in v1.14.0
MultiSelectImpl prompts the user to select multiple options from a list using the default theme.
func PasswordImpl ¶ added in v1.14.0
PasswordImpl prompts the user for a secret text input using the default theme.
Types ¶
type MultiSpinner ¶
type MultiSpinner struct {
// contains filtered or unexported fields
}
MultiSpinner manages multiple concurrent spinners.
func NewMultiSpinner ¶
func NewMultiSpinner() (*MultiSpinner, error)
NewMultiSpinner creates a new multi-spinner manager.
func (*MultiSpinner) AddSpinner ¶
func (m *MultiSpinner) AddSpinner(text string) ProgressSpinner
AddSpinner adds a new spinner to the multi-printer display.
type ProgressSpinner ¶ added in v1.14.0
type ProgressSpinner interface {
UpdateText(text string)
Success(text ...interface{})
Fail(text ...interface{})
Warning(text ...interface{})
Info(text ...interface{})
}
ProgressSpinner defines the interface for spinner operations.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner wraps the mpb.Progress container and a single bar. It's designed to manage a single progress bar and allow logging messages above the bar without disrupting it.
func NewProgressSpinner ¶
NewProgressSpinner creates a spinner that displays progress as a bar.
func NewSpinner ¶
NewSpinner creates a new spinner with a default indeterminate style.
func (*Spinner) SetProgressBar ¶
SetProgressBar sets the progress of the bar. Progress should be from 0.0 to 1.0.
func (*Spinner) Start ¶
func (s *Spinner) Start()
Start does nothing in this implementation, as the bar is visible on creation.
func (*Spinner) Stop ¶
func (s *Spinner) Stop()
Stop marks the bar as completed and waits for the progress container to finish.
func (*Spinner) UpdateMessage ¶
UpdateMessage updates the message displayed next to the spinner/bar.