Documentation
¶
Overview ¶
Package tui provides shared TUI components for Spectr CLI interactive modes.
Index ¶
- Constants
- func ApplyTableStyles(t *table.Model)
- func ChoiceStyle() lipgloss.Style
- func CopyToClipboard(text string) error
- func HelpStyle() lipgloss.Style
- func SelectedStyle() lipgloss.Style
- func TitleStyle() lipgloss.Style
- func TruncateString(s string, maxLen int) string
- type Action
- type ActionHandler
- type ActionResult
- type MenuConfig
- type MenuPicker
- func (m *MenuPicker) Init() tea.Cmd
- func (m *MenuPicker) Quitting() bool
- func (m *MenuPicker) Run() (int, error)
- func (m *MenuPicker) Selected() int
- func (m *MenuPicker) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (m *MenuPicker) View() string
- func (m *MenuPicker) WithSelectHandler(handler func(index int) (tea.Model, tea.Cmd)) *MenuPicker
- type TableConfig
- type TablePicker
- func (p *TablePicker) Init() tea.Cmd
- func (p *TablePicker) Result() *ActionResult
- func (p *TablePicker) Run() (*ActionResult, error)
- func (p *TablePicker) SetFooterExtra(extra string)
- func (p *TablePicker) SetRows(rows []table.Row)
- func (p *TablePicker) Table() *table.Model
- func (p *TablePicker) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (p *TablePicker) UpdateHelpText()
- func (p *TablePicker) View() string
- func (p *TablePicker) WithAction(key, description string, handler ActionHandler) *TablePicker
- func (p *TablePicker) WithProjectPath(path string) *TablePicker
Constants ¶
const ( ColorBorder = "240" ColorHeader = "99" ColorSelected = "229" ColorHighlight = "57" ColorHelp = "240" )
Color constants used across TUI components
const (
// DefaultTableHeight is the default number of visible rows.
DefaultTableHeight = 10
)
const ( // EllipsisMinLength is the minimum string length before // truncation adds ellipsis. EllipsisMinLength = 3 )
Variables ¶
This section is empty.
Functions ¶
func ApplyTableStyles ¶
ApplyTableStyles applies the default Spectr styling to a table.
func ChoiceStyle ¶
ChoiceStyle returns the style for unselected choices.
func CopyToClipboard ¶
CopyToClipboard copies text to clipboard using native or OSC 52.
func SelectedStyle ¶
SelectedStyle returns the style for selected items.
func TruncateString ¶
TruncateString truncates a string and adds ellipsis if needed.
Types ¶
type Action ¶
type Action struct {
Key string // The key binding (e.g., "e", "a", "enter")
Description string // Human-readable description for help text
Handler ActionHandler // The function to call when key is pressed
}
Action represents a configurable key action for TablePicker.
type ActionHandler ¶
type ActionHandler func(row table.Row) (tea.Cmd, *ActionResult)
ActionHandler is a function that handles a key action on a selected row. It receives the selected row and returns a tea.Cmd and an optional result.
type ActionResult ¶
type ActionResult struct {
// ID is the selected item ID (usually from first column).
ID string
// Quit indicates the TUI should exit.
Quit bool
// Cancelled indicates the user cancelled.
Cancelled bool
// Copied indicates an ID was copied to clipboard.
Copied bool
// ArchiveRequested indicates archive action was requested.
ArchiveRequested bool
// Error contains any error from the action.
Error error
// Custom allows actions to pass custom data.
Custom any
}
ActionResult represents the result of an action.
type MenuConfig ¶
type MenuConfig struct {
// Title is the menu title.
Title string
// Choices are the menu options.
Choices []string
// SelectHandler is called when an option is selected.
// Receives the index of the selected choice.
SelectHandler func(index int) tea.Cmd
}
MenuConfig holds configuration for MenuPicker.
type MenuPicker ¶
type MenuPicker struct {
// contains filtered or unexported fields
}
MenuPicker is a simple menu-based selector. It provides a vertical list of choices with navigation and selection support.
func NewMenuPicker ¶
func NewMenuPicker( config MenuConfig, ) *MenuPicker
NewMenuPicker creates a new MenuPicker with the given configuration.
Selection behavior:
- If config.SelectHandler is provided, it will be called on selection
- If config.SelectHandler is nil, the menu will quit on selection (default)
This default allows callers to create simple menus without specifying a handler when they only need to retrieve the selected index via Run().
func (*MenuPicker) Quitting ¶
func (m *MenuPicker) Quitting() bool
Quitting returns whether the menu was quit.
func (*MenuPicker) Run ¶
func (m *MenuPicker) Run() (int, error)
Run runs the MenuPicker and returns the selected index, or -1 if cancelled.
func (*MenuPicker) Selected ¶
func (m *MenuPicker) Selected() int
Selected returns the index of the selected choice.
func (*MenuPicker) WithSelectHandler ¶
func (m *MenuPicker) WithSelectHandler( handler func(index int) (tea.Model, tea.Cmd), ) *MenuPicker
WithSelectHandler sets the handler for menu selection. The handler receives the selected index and can return a new model to transition to.
type TableConfig ¶
type TableConfig struct {
// Columns defines the table columns.
Columns []table.Column
// Rows contains the table data.
Rows []table.Row
// Height is the visible height of the table.
Height int
// Actions is a map of key bindings to actions.
Actions map[string]Action
// HelpText is custom help text; if empty, generated from actions.
HelpText string
// ProjectPath is the project root for file operations.
ProjectPath string
FooterExtra string
}
TableConfig holds configuration for TablePicker.
type TablePicker ¶
type TablePicker struct {
// contains filtered or unexported fields
}
TablePicker is a configurable table-based item selector.
func NewTablePicker ¶
func NewTablePicker( config *TableConfig, ) *TablePicker
NewTablePicker creates a new TablePicker with the given configuration.
func (*TablePicker) Result ¶
func (p *TablePicker) Result() *ActionResult
Result returns the action result after the picker has quit.
func (*TablePicker) Run ¶
func (p *TablePicker) Run() (*ActionResult, error)
Run runs the TablePicker and returns the result.
func (*TablePicker) SetFooterExtra ¶
func (p *TablePicker) SetFooterExtra( extra string, )
SetFooterExtra sets additional footer text.
func (*TablePicker) SetRows ¶
func (p *TablePicker) SetRows(rows []table.Row)
SetRows updates the table rows and regenerates help text.
func (*TablePicker) Table ¶
func (p *TablePicker) Table() *table.Model
Table returns the underlying table model for advanced use cases.
func (*TablePicker) UpdateHelpText ¶
func (p *TablePicker) UpdateHelpText()
UpdateHelpText regenerates the help text with the current row count.
func (*TablePicker) WithAction ¶
func (p *TablePicker) WithAction( key, description string, handler ActionHandler, ) *TablePicker
WithAction adds a key action to the picker.
func (*TablePicker) WithProjectPath ¶
func (p *TablePicker) WithProjectPath( path string, ) *TablePicker
WithProjectPath sets the project path for file operations.