Documentation
¶
Overview ¶
Package commandpalette renders a fuzzy-filtered command picker as a modal surface. Consumers supply a list of commands, render the View, route key events through Update, and observe SelectMsg / CancelMsg.
The default matcher is case-insensitive substring on Title (and on Group when present). Replace the matcher by setting a function via WithMatcher — the function returns a non-zero score to keep a command, zero to drop. Higher scores rank earlier.
Index ¶
- func SubstringMatcher(cmd Command, query string) int
- type CancelMsg
- type Command
- type Matcher
- type Palette
- func (p Palette) Cursor() int
- func (p Palette) Filter() string
- func (p Palette) Init() tea.Cmd
- func (p Palette) Update(msg tea.Msg) (Palette, tea.Cmd)
- func (p Palette) View() string
- func (p Palette) WithCommands(cmds []Command) Palette
- func (p Palette) WithFilter(s string) Palette
- func (p Palette) WithMatcher(m Matcher) Palette
- func (p Palette) WithPlaceholder(s string) Palette
- func (p Palette) WithSize(w, h int) Palette
- func (p Palette) WithTitle(s string) Palette
- type SelectMsg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SubstringMatcher ¶
SubstringMatcher is the default matcher. Case-insensitive substring match on Title and Group. Returns 100 when query is empty (every command passes), or the inverse position of the match (higher = earlier in the string).
Types ¶
type Command ¶
type Command struct {
ID string // stable identifier returned in SelectMsg
Title string // primary label rendered on the row
Description string // optional secondary label rendered under Title
Group string // optional grouping label rendered as a section header
Keybinding string // optional shortcut hint rendered right-aligned
}
Command is one row the user can select.
type Matcher ¶
Matcher returns a score for cmd against query. Zero score drops cmd from the result list. Higher scores sort earlier. The default matcher does a case-insensitive substring match on Title and Group.
type Palette ¶
type Palette struct {
// contains filtered or unexported fields
}
Palette is a Bubble Tea model for a filterable command picker.
func New ¶
New constructs a Palette with the default substring matcher. No commands are loaded; call WithCommands.
func (Palette) WithCommands ¶
WithCommands sets the command list. Cursor resets to 0.
func (Palette) WithFilter ¶
WithFilter presets the filter text.
func (Palette) WithMatcher ¶
WithMatcher replaces the scoring function. Pass nil to restore the default.
func (Palette) WithPlaceholder ¶
WithPlaceholder sets the filter input placeholder.
