Documentation
¶
Overview ¶
Package components provides reusable bubbletea TUI components for the Nexus CLI's interactive wizards.
This file implements a Yes/No confirmation prompt built on bubbletea. It presents a binary choice with a highlighted default, left/right arrow key toggling, and enter to confirm. The prompt renders in the familiar "Y/n" or "y/N" style, with the current selection highlighted using the theme's primary color.
Usage:
model := components.NewConfirm("Enable authentication?", true)
// Use as a bubbletea model inside a parent model or program.
Package components provides reusable bubbletea TUI components for the Nexus CLI's interactive wizards.
This file implements a multi-select list component built on top of bubbletea. It presents a vertical list of items, each with a name and description, that the user can toggle on or off with the space bar. The component renders checkbox indicators ([x] / [ ]) with colored names and muted descriptions.
Usage:
items := []components.MultiSelectItem{
{Name: "REST", Description: "HTTP/JSON API via Fiber"},
{Name: "gRPC", Description: "Protocol Buffers over HTTP/2"},
}
model := components.NewMultiSelect("Select protocols:", items)
// Use as a bubbletea model inside a parent model or program.
Package components provides reusable bubbletea TUI components for the Nexus CLI's interactive wizards.
This file implements a single-select list component built on top of bubbletea. It presents a vertical list of items, each with a name and description, where the user can choose exactly one option. The component renders a radio-button style indicator (● / ○) with colored names and muted descriptions.
This is distinct from the MultiSelect component — only one item can be selected at a time, and pressing space or enter on an item selects it and optionally confirms the selection.
Usage:
items := []components.SingleSelectItem{
{Name: "SQLite", Description: "Zero-config, pure Go, file-based"},
{Name: "PostgreSQL", Description: "Production-grade relational database"},
{Name: "None", Description: "In-memory only (for prototyping)"},
}
model := components.NewSingleSelect("Select database:", items)
// Use as a bubbletea model inside a parent model or program.
Package components provides reusable bubbletea TUI components for the Nexus CLI's interactive wizards.
This file implements a styled spinner component built on top of the bubbles/spinner model. It displays an animated spinner icon alongside a message string, styled with the theme's primary color. The spinner is used for any operation that takes longer than ~200ms to provide visual feedback that work is in progress.
The component wraps the bubbles spinner and adds:
- A configurable message displayed to the right of the spinner icon
- Automatic styling with the theme's primary color
- A "done" state that replaces the spinner with a success checkmark
- Focus control so the spinner can be embedded in multi-step wizards
Usage:
model := components.NewSpinner("Generating project...")
// Use as a bubbletea model inside a parent model or program.
Package components provides reusable bubbletea TUI components for the Nexus CLI's interactive wizards.
This file implements a summary/review panel component that displays key-value pairs inside a bordered box styled with the theme colors. It is used on the review screen before code generation to give the user a clear overview of all their selections.
Features:
- Left column: keys rendered with KeyStyle (bold, primary, right-aligned)
- Right column: values rendered with ValueStyle (light text)
- List values rendered as comma-separated colored tags
- Wrapped in a rounded border box with the theme's primary color
- Optional title displayed above the key-value pairs
Usage:
s := components.NewSummary("Review Your Selections")
s.AddRow("Project", "my-backend")
s.AddRow("Module", "github.com/user/my-backend")
s.AddListRow("Protocols", []string{"REST", "gRPC", "WebSocket"})
// Render with s.View() inside a parent model or standalone.
Package components provides reusable bubbletea TUI components for the Nexus CLI's interactive wizards.
This file implements a styled text input component built on top of the bubbles/textinput model. It adds a label displayed above the input field, placeholder text, and inline validation that renders a red border and error message when the current value is invalid.
The component delegates all cursor movement, character insertion, and deletion to the underlying bubbles textinput — we only add visual chrome and validation on top.
Usage:
validate := func(s string) error {
if s == "" { return fmt.Errorf("project name is required") }
return nil
}
model := components.NewTextInput("Project name:", "my-backend", validate)
// Use as a bubbletea model inside a parent model or program.
Index ¶
- type Confirm
- type ConfirmMsg
- type MultiSelect
- func (m MultiSelect) Confirmed() bool
- func (m MultiSelect) Init() tea.Cmd
- func (m MultiSelect) Items() []MultiSelectItem
- func (m *MultiSelect) Reset()
- func (m MultiSelect) SelectedItems() []MultiSelectItem
- func (m MultiSelect) SelectedNames() []string
- func (m *MultiSelect) SetFocused(focused bool)
- func (m *MultiSelect) SetItems(items []MultiSelectItem)
- func (m MultiSelect) Update(msg tea.Msg) (MultiSelect, tea.Cmd)
- func (m MultiSelect) View() string
- type MultiSelectItem
- type MultiSelectMsg
- type SingleSelect
- func (m SingleSelect) Confirmed() bool
- func (m SingleSelect) Init() tea.Cmd
- func (m SingleSelect) Items() []SingleSelectItem
- func (m *SingleSelect) Reset()
- func (m SingleSelect) SelectedItem() SingleSelectItem
- func (m SingleSelect) SelectedName() string
- func (m SingleSelect) SelectedValue() string
- func (m *SingleSelect) SetFocused(focused bool)
- func (m *SingleSelect) SetItems(items []SingleSelectItem)
- func (m *SingleSelect) SetSelected(index int)
- func (m *SingleSelect) SetSelectedByValue(value string)
- func (m SingleSelect) Update(msg tea.Msg) (SingleSelect, tea.Cmd)
- func (m SingleSelect) View() string
- type SingleSelectItem
- type SingleSelectMsg
- type Spinner
- func (m Spinner) Done() bool
- func (m Spinner) Init() tea.Cmd
- func (m Spinner) Message() string
- func (m *Spinner) Reset()
- func (m *Spinner) SetDone(done bool)
- func (m *Spinner) SetDoneMessage(msg string)
- func (m *Spinner) SetFocused(focused bool)
- func (m *Spinner) SetMessage(msg string)
- func (m *Spinner) SetSpinnerStyle(style spinner.Spinner)
- func (m Spinner) Tick() tea.Cmd
- func (m Spinner) Update(msg tea.Msg) (Spinner, tea.Cmd)
- func (m Spinner) View() string
- type SpinnerDoneMsg
- type Summary
- func (m *Summary) AddListRow(key string, values []string)
- func (m *Summary) AddRow(key, value string)
- func (m *Summary) ClearRows()
- func (m Summary) Rows() []SummaryRow
- func (m *Summary) SetKeyWidth(w int)
- func (m *Summary) SetRows(rows []SummaryRow)
- func (m *Summary) SetTitle(title string)
- func (m Summary) View() string
- type SummaryRow
- type TextInput
- func (m TextInput) Confirmed() bool
- func (m TextInput) Err() error
- func (m TextInput) Init() tea.Cmd
- func (m *TextInput) Reset()
- func (m *TextInput) SetCharLimit(n int)
- func (m *TextInput) SetFocused(focused bool)
- func (m *TextInput) SetValue(v string)
- func (m *TextInput) SetWidth(w int)
- func (m TextInput) Update(msg tea.Msg) (TextInput, tea.Cmd)
- func (m TextInput) Value() string
- func (m TextInput) View() string
- type TextInputMsg
- type ValidateFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Confirm ¶
type Confirm struct {
// contains filtered or unexported fields
}
Confirm is a bubbletea model that renders an interactive Yes/No prompt with keyboard navigation and styled output.
func NewConfirm ¶
NewConfirm creates a new Confirm model with the given label and default value. If defaultYes is true, the prompt defaults to "Yes" and renders as "Y/n". If false, it defaults to "No" and renders as "y/N". The component starts focused by default.
func (Confirm) Confirmed ¶
Confirmed returns whether the user has pressed enter to finalize the choice.
func (*Confirm) Reset ¶
func (m *Confirm) Reset()
Reset clears the confirmed state and restores the default value, returning the component to its initial interactive state.
func (*Confirm) SetFocused ¶
SetFocused sets whether the component accepts keyboard input.
func (Confirm) Update ¶
Update handles keyboard input for toggling and confirming the selection.
Key bindings:
- ← / h / y — select Yes
- → / l / n — select No
- tab — toggle between Yes and No
- enter — confirm the current selection and emit ConfirmMsg
type ConfirmMsg ¶
type ConfirmMsg struct {
// Value is true if the user selected "Yes", false for "No".
Value bool
}
ConfirmMsg is sent when the user confirms their choice by pressing enter. Parent models should handle this message to receive the boolean result.
type MultiSelect ¶
type MultiSelect struct {
// contains filtered or unexported fields
}
MultiSelect is a bubbletea model that renders an interactive multi-select list with keyboard navigation, space-to-toggle, and enter-to-confirm.
func NewMultiSelect ¶
func NewMultiSelect(title string, items []MultiSelectItem) MultiSelect
NewMultiSelect creates a new MultiSelect model with the given title and items. All items start unselected unless their Selected field is pre-set. The component starts focused by default.
func (MultiSelect) Confirmed ¶
func (m MultiSelect) Confirmed() bool
Confirmed returns whether the user has pressed enter to finalize selection.
func (MultiSelect) Init ¶
func (m MultiSelect) Init() tea.Cmd
Init returns nil — this component has no initial command.
func (MultiSelect) Items ¶
func (m MultiSelect) Items() []MultiSelectItem
Items returns the current list of items (including their selected state).
func (*MultiSelect) Reset ¶
func (m *MultiSelect) Reset()
Reset clears the confirmed state and deselects all items, returning the component to its initial interactive state.
func (MultiSelect) SelectedItems ¶
func (m MultiSelect) SelectedItems() []MultiSelectItem
SelectedItems returns a slice of items that are currently toggled on.
func (MultiSelect) SelectedNames ¶
func (m MultiSelect) SelectedNames() []string
SelectedNames returns just the names of the selected items, which is convenient for passing to downstream configuration structs.
func (*MultiSelect) SetFocused ¶
func (m *MultiSelect) SetFocused(focused bool)
SetFocused sets whether the component accepts keyboard input.
func (*MultiSelect) SetItems ¶
func (m *MultiSelect) SetItems(items []MultiSelectItem)
SetItems replaces the current item list. The cursor is reset to zero.
func (MultiSelect) Update ¶
func (m MultiSelect) Update(msg tea.Msg) (MultiSelect, tea.Cmd)
Update handles keyboard input for navigation, toggling, and confirmation.
Key bindings:
- ↑ / k — move cursor up
- ↓ / j — move cursor down
- space — toggle the item under the cursor
- a — select all items
- n — deselect all items
- enter — confirm selection and emit MultiSelectMsg
func (MultiSelect) View ¶
func (m MultiSelect) View() string
View renders the multi-select list with checkbox indicators, a cursor, and a footer help line.
type MultiSelectItem ¶
type MultiSelectItem struct {
// Name is the primary label displayed next to the checkbox.
Name string
// Description is a short explanation shown to the right of the name
// in muted text. Can be empty.
Description string
// Selected indicates whether this item is currently toggled on.
Selected bool
}
MultiSelectItem represents a single option in the multi-select list. Each item has a display name, an optional description, and a selected state.
type MultiSelectMsg ¶
type MultiSelectMsg struct {
// Selected contains the items that were toggled on at the time of
// confirmation.
Selected []MultiSelectItem
}
MultiSelectMsg is sent when the user confirms their selection by pressing enter. Parent models should handle this message to receive the results.
type SingleSelect ¶
type SingleSelect struct {
// contains filtered or unexported fields
}
SingleSelect is a bubbletea model that renders an interactive single-select list with keyboard navigation, space/enter to select and confirm.
func NewSingleSelect ¶
func NewSingleSelect(title string, items []SingleSelectItem) SingleSelect
NewSingleSelect creates a new SingleSelect model with the given title and items. The first item is selected by default. The component starts focused by default.
func (SingleSelect) Confirmed ¶
func (m SingleSelect) Confirmed() bool
Confirmed returns whether the user has pressed enter to finalize selection.
func (SingleSelect) Init ¶
func (m SingleSelect) Init() tea.Cmd
Init returns nil — this component has no initial command.
func (SingleSelect) Items ¶
func (m SingleSelect) Items() []SingleSelectItem
Items returns the current list of items.
func (*SingleSelect) Reset ¶
func (m *SingleSelect) Reset()
Reset clears the confirmed state and resets the selection to the first item, returning the component to its initial interactive state.
func (SingleSelect) SelectedItem ¶
func (m SingleSelect) SelectedItem() SingleSelectItem
SelectedItem returns the currently selected item.
func (SingleSelect) SelectedName ¶
func (m SingleSelect) SelectedName() string
SelectedName returns the name of the currently selected item.
func (SingleSelect) SelectedValue ¶
func (m SingleSelect) SelectedValue() string
SelectedValue returns the effective value of the currently selected item. This is the Value field if set, otherwise the Name.
func (*SingleSelect) SetFocused ¶
func (m *SingleSelect) SetFocused(focused bool)
SetFocused sets whether the component accepts keyboard input.
func (*SingleSelect) SetItems ¶
func (m *SingleSelect) SetItems(items []SingleSelectItem)
SetItems replaces the current item list. The cursor and selection are reset to zero.
func (*SingleSelect) SetSelected ¶
func (m *SingleSelect) SetSelected(index int)
SetSelected sets the selected item by index. If the index is out of range, it is clamped to the valid range.
func (*SingleSelect) SetSelectedByValue ¶
func (m *SingleSelect) SetSelectedByValue(value string)
SetSelectedByValue sets the selected item by matching the Value (or Name fallback) field. If no match is found, the selection is unchanged.
func (SingleSelect) Update ¶
func (m SingleSelect) Update(msg tea.Msg) (SingleSelect, tea.Cmd)
Update handles keyboard input for navigation, selection, and confirmation.
Key bindings:
- ↑ / k — move cursor up
- ↓ / j — move cursor down
- space — select the item under the cursor
- enter — select the item under the cursor and confirm
func (SingleSelect) View ¶
func (m SingleSelect) View() string
View renders the single-select list with radio indicators, a cursor, and a footer help line.
type SingleSelectItem ¶
type SingleSelectItem struct {
// Name is the primary label displayed next to the radio indicator.
Name string
// Description is a short explanation shown to the right of the name
// in muted text. Can be empty.
Description string
// Value is the internal value associated with this item. If empty,
// the Name is used as the value. This allows display names to differ
// from the values passed to downstream logic.
Value string
}
SingleSelectItem represents a single option in the single-select list. Each item has a display name and an optional description.
type SingleSelectMsg ¶
type SingleSelectMsg struct {
// Selected is the item that was chosen at the time of confirmation.
Selected SingleSelectItem
}
SingleSelectMsg is sent when the user confirms their selection by pressing enter. Parent models should handle this message to receive the result.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner is a bubbletea model that renders an animated spinner icon with a message string. It wraps the bubbles/spinner model and adds theme styling, a configurable message, and a done state.
func NewSpinner ¶
NewSpinner creates a new Spinner model with the given message. The spinner uses the "Dot" style by default and is colored with the theme's primary color. The component starts focused by default so it begins animating immediately.
func (Spinner) Init ¶
Init returns the initial tick command from the underlying spinner so the animation begins immediately.
func (*Spinner) Reset ¶
func (m *Spinner) Reset()
Reset restores the spinner to its initial state: not done, original message, and ready to animate.
func (*Spinner) SetDone ¶
SetDone manually sets the done state. Prefer sending a SpinnerDoneMsg through the bubbletea update loop when possible.
func (*Spinner) SetDoneMessage ¶
SetDoneMessage sets the message displayed when the spinner transitions to the done state. If not set, the original message is used.
func (*Spinner) SetFocused ¶
SetFocused sets whether the component processes tick messages to animate the spinner. When unfocused, the spinner freezes at its current frame.
func (*Spinner) SetMessage ¶
SetMessage updates the message displayed next to the spinner. This is useful for multi-step operations where the status text changes over time.
func (*Spinner) SetSpinnerStyle ¶
SetSpinnerStyle sets the spinner animation style. Available styles from the bubbles/spinner package include Dot, Line, MiniDot, Jump, Pulse, Points, Globe, Moon, Monkey, Meter, and Hamburger.
func (Spinner) Tick ¶
Tick returns the tick command needed to keep the spinner animation running. Parent models should call this in their Init() or when embedding the spinner in a larger model to ensure the animation starts.
type SpinnerDoneMsg ¶
type SpinnerDoneMsg struct{}
SpinnerDoneMsg is sent when the spinner's work is complete. Parent models can send this message to transition the spinner into its "done" state, which replaces the animated icon with a success checkmark.
type Summary ¶
type Summary struct {
// contains filtered or unexported fields
}
Summary is a display-only component (not interactive) that renders a bordered box containing key-value pairs. It implements a View() method compatible with bubbletea's rendering pattern, but does not process any messages — it is purely visual.
func NewSummary ¶
NewSummary creates a new Summary panel with the given title. The title is displayed at the top of the bordered box. Pass an empty string to omit it.
func (*Summary) AddListRow ¶
AddListRow appends a key with multiple values to the summary. The values are rendered as comma-separated colored tags in the right column.
func (*Summary) AddRow ¶
AddRow appends a plain key-value pair to the summary. The value is rendered as a single string in the right column.
func (*Summary) ClearRows ¶
func (m *Summary) ClearRows()
ClearRows removes all rows from the summary.
func (Summary) Rows ¶
func (m Summary) Rows() []SummaryRow
Rows returns a copy of the current rows for inspection.
func (*Summary) SetKeyWidth ¶
SetKeyWidth manually overrides the key column width. By default it is automatically calculated from the longest key name.
func (*Summary) SetRows ¶
func (m *Summary) SetRows(rows []SummaryRow)
SetRows replaces all rows in the summary with the provided slice. This is useful when rebuilding the summary from scratch (e.g., after navigating back through the wizard).
type SummaryRow ¶
type SummaryRow struct {
// Key is the label displayed in the left column.
Key string
// Value is the plain string value displayed in the right column.
// Ignored if ListValue is non-empty.
Value string
// ListValue holds multiple values that are rendered as comma-separated
// colored tags. When non-empty, this takes precedence over Value.
ListValue []string
}
SummaryRow represents a single key-value pair in the summary panel. The value can be either a plain string or a list of strings rendered as tags.
type TextInput ¶
type TextInput struct {
// contains filtered or unexported fields
}
TextInput is a bubbletea model that renders a labeled text input field with optional placeholder text and inline validation feedback.
func NewTextInput ¶
func NewTextInput(label, placeholder string, validate ValidateFunc) TextInput
NewTextInput creates a new TextInput model with the given label, placeholder text, and optional validation function. Pass nil for validate to accept any input. The component starts focused by default.
func (TextInput) Confirmed ¶
Confirmed returns whether the user has pressed enter with a valid value.
func (TextInput) Init ¶
Init returns the blink command from the underlying textinput so the cursor animates immediately.
func (*TextInput) Reset ¶
func (m *TextInput) Reset()
Reset clears the input value, validation state, and confirmed flag, returning the component to its initial interactive state.
func (*TextInput) SetCharLimit ¶
SetCharLimit sets the maximum number of characters the input field accepts.
func (*TextInput) SetFocused ¶
SetFocused sets whether the component accepts keyboard input and shows the blinking cursor.
func (*TextInput) SetValue ¶
SetValue programmatically sets the input field text. This is useful for pre-filling a value (e.g., when a project name is passed via CLI args).
func (TextInput) Update ¶
Update handles keyboard input by delegating to the inner textinput and running validation on every change. Enter confirms the value if valid.
Key bindings:
- enter — attempt to confirm the current value
- all others — delegated to the bubbles textinput
type TextInputMsg ¶
type TextInputMsg struct {
// Value is the confirmed, validated text.
Value string
}
TextInputMsg is sent when the user confirms the input by pressing enter and the value passes validation. Parent models should handle this message to receive the final value.
type ValidateFunc ¶
ValidateFunc is a function that validates a text input value. It returns nil if the value is valid, or an error describing what is wrong. The error message is displayed inline beneath the input field.