Documentation
¶
Overview ¶
Package tui provides interactive terminal user interface components. It encapsulates TUI library specifics and provides clean interfaces for testing.
Index ¶
- Variables
- func IsInteractive() bool
- func IsTTY() bool
- func QuickSpinner(title string, action func()) error
- func QuickSpinnerWithErr(ctx context.Context, title string, action func(context.Context) error) error
- type Choice
- type MockCall
- type MockPrompter
- func (m *MockPrompter) CallCount(method string) int
- func (m *MockPrompter) ConfirmOperation(message string) (bool, error)
- func (m *MockPrompter) LastCall(method string) *MockCall
- func (m *MockPrompter) PromptModuleSelection(modules []*workspace.Module) (Selection, error)
- func (m *MockPrompter) Reset()
- func (m *MockPrompter) WithConfirmError(err error) *MockPrompter
- func (m *MockPrompter) WithConfirmResult(result bool) *MockPrompter
- func (m *MockPrompter) WithSelectionError(err error) *MockPrompter
- func (m *MockPrompter) WithSelectionResult(result Selection) *MockPrompter
- type ModulePrompt
- type MultiModuleSpinner
- type ProgressReporter
- type Prompter
- type Selection
- type Spinner
- type SpinnerOption
- type SpinnerType
Constants ¶
This section is empty.
Variables ¶
var ErrCanceled = fmt.Errorf("operation canceled by user")
ErrCanceled is returned when the user cancels the operation.
Functions ¶
func IsInteractive ¶
func IsInteractive() bool
IsInteractive determines if the current environment supports interactive prompts. It returns false in the following cases:
- stdout is not a terminal (redirected to file, pipe, etc.)
- running in a CI/CD environment (detected via environment variables)
This function is used to automatically skip TUI prompts in non-interactive contexts.
func IsTTY ¶
func IsTTY() bool
IsTTY checks if stdout is a terminal. This is a lower-level check than IsInteractive.
func QuickSpinner ¶
QuickSpinner runs a simple spinner with the given title and action. This is a convenience function for simple use cases.
Types ¶
type MockPrompter ¶
type MockPrompter struct {
// SelectionResult is the pre-configured selection to return.
SelectionResult Selection
// SelectionError is the error to return from PromptModuleSelection.
SelectionError error
// ConfirmResult is the result to return from ConfirmOperation.
ConfirmResult bool
// ConfirmError is the error to return from ConfirmOperation.
ConfirmError error
// Calls records all method invocations for assertion.
Calls []MockCall
// contains filtered or unexported fields
}
MockPrompter is a mock implementation of Prompter for testing. It allows tests to control the selection results without requiring user interaction.
func NewMockPrompter ¶
func NewMockPrompter() *MockPrompter
NewMockPrompter creates a new MockPrompter.
func (*MockPrompter) CallCount ¶
func (m *MockPrompter) CallCount(method string) int
CallCount returns the number of times a method was called.
func (*MockPrompter) ConfirmOperation ¶
func (m *MockPrompter) ConfirmOperation(message string) (bool, error)
ConfirmOperation returns the pre-configured ConfirmResult.
func (*MockPrompter) LastCall ¶
func (m *MockPrompter) LastCall(method string) *MockCall
LastCall returns the most recent call to the specified method. Returns nil if the method was never called.
func (*MockPrompter) PromptModuleSelection ¶
func (m *MockPrompter) PromptModuleSelection(modules []*workspace.Module) (Selection, error)
PromptModuleSelection returns the pre-configured SelectionResult.
func (*MockPrompter) Reset ¶
func (m *MockPrompter) Reset()
Reset clears all recorded calls and resets state.
func (*MockPrompter) WithConfirmError ¶
func (m *MockPrompter) WithConfirmError(err error) *MockPrompter
WithConfirmError sets the confirm error and returns the mock for chaining.
func (*MockPrompter) WithConfirmResult ¶
func (m *MockPrompter) WithConfirmResult(result bool) *MockPrompter
WithConfirmResult sets the confirm result and returns the mock for chaining.
func (*MockPrompter) WithSelectionError ¶
func (m *MockPrompter) WithSelectionError(err error) *MockPrompter
WithSelectionError sets the selection error and returns the mock for chaining.
func (*MockPrompter) WithSelectionResult ¶
func (m *MockPrompter) WithSelectionResult(result Selection) *MockPrompter
WithSelectionResult sets the selection result and returns the mock for chaining.
type ModulePrompt ¶
type ModulePrompt struct {
// contains filtered or unexported fields
}
ModulePrompt implements the Prompter interface using charmbracelet/huh. It provides an interactive TUI for module selection in multi-module workspaces.
func NewModulePrompt ¶
func NewModulePrompt(modules []*workspace.Module) *ModulePrompt
NewModulePrompt creates a new ModulePrompt with the given modules.
func (*ModulePrompt) ConfirmOperation ¶
func (p *ModulePrompt) ConfirmOperation(message string) (bool, error)
ConfirmOperation asks for yes/no confirmation.
func (*ModulePrompt) PromptModuleSelection ¶
func (p *ModulePrompt) PromptModuleSelection(modules []*workspace.Module) (Selection, error)
PromptModuleSelection shows an interactive module selection UI. First, it presents a choice: apply to all, select specific, or cancel. If "select specific" is chosen, it shows a multi-select checkbox interface.
type MultiModuleSpinner ¶
type MultiModuleSpinner struct {
// contains filtered or unexported fields
}
MultiModuleSpinner shows progress for multi-module operations.
func NewMultiModuleSpinner ¶
func NewMultiModuleSpinner(total int, accessible bool) *MultiModuleSpinner
NewMultiModuleSpinner creates a spinner for multi-module operations.
func (*MultiModuleSpinner) RunEach ¶
func (m *MultiModuleSpinner) RunEach( ctx context.Context, moduleNames []string, action func(ctx context.Context, idx int) error, ) error
RunEach executes an action for each item with progress indication. The action receives the current index and should return an error if it fails.
type ProgressReporter ¶
type ProgressReporter interface {
// Start begins showing progress.
Start(title string)
// Update updates the current progress state.
Update(current, total int, currentModule string)
// Finish completes the progress display.
Finish()
}
ProgressReporter provides a way to update progress during multi-module operations.
type Prompter ¶
type Prompter interface {
// PromptModuleSelection shows interactive module selection UI.
// Returns a Selection indicating user choices or an error.
// Returns ErrCanceled if the user cancels the operation.
PromptModuleSelection(modules []*workspace.Module) (Selection, error)
// ConfirmOperation asks for yes/no confirmation.
// Returns true if confirmed, false if declined.
ConfirmOperation(message string) (bool, error)
}
Prompter abstracts interactive prompts for module selection. This interface enables dependency injection and testing with mock implementations.
type Selection ¶
type Selection struct {
// All indicates if the user selected "apply to all modules".
All bool
// Modules contains the names of specific modules selected.
// Empty if All is true or if operation was canceled.
Modules []string
// Canceled indicates if the user canceled the selection.
Canceled bool
}
Selection represents the user's module selection from the TUI prompt.
func CanceledSelection ¶
func CanceledSelection() Selection
CanceledSelection returns a Selection marked as canceled.
func SelectedModules ¶
SelectedModules returns a Selection with specific module names.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner provides progress indication for long-running operations. It wraps charmbracelet/huh/spinner for a consistent interface.
func NewSpinner ¶
func NewSpinner(opts ...SpinnerOption) *Spinner
NewSpinner creates a new Spinner with the given options.
type SpinnerOption ¶
type SpinnerOption func(*Spinner)
SpinnerOption configures a Spinner.
func WithAccessibleMode ¶
func WithAccessibleMode(accessible bool) SpinnerOption
WithAccessibleMode enables accessible mode (no animations).
func WithSpinnerTitle ¶
func WithSpinnerTitle(title string) SpinnerOption
WithSpinnerTitle sets the spinner's title message.
func WithSpinnerType ¶
func WithSpinnerType(t SpinnerType) SpinnerOption
WithSpinnerType sets the spinner's animation style.
type SpinnerType ¶
type SpinnerType int
SpinnerType represents different spinner animation styles.
const ( // SpinnerLine uses line-based animation. SpinnerLine SpinnerType = iota // SpinnerDots uses dots animation. SpinnerDots // SpinnerMiniDot uses mini dot animation. SpinnerMiniDot // SpinnerPulse uses pulse animation. SpinnerPulse )