Documentation
¶
Overview ¶
Package picker is a fuzzy-filtered selection overlay for nook. It is the underlying primitive behind file picker, buffer picker, symbol picker, and branch picker.
An Item carries a Title (rendered), an optional Subtitle, optional Group label, and an opaque Value. Consumers feed items in, route keys through Update, and observe SelectMsg / CancelMsg.
The default matcher is a subsequence-with-bonuses scorer (start-of-string, word-boundary, consecutive). Replace it with WithMatcher when needed.
Index ¶
- func Score(target, query string) int
- func SubsequenceMatcher(it Item, query string) int
- type CancelMsg
- type Item
- type Matcher
- type Picker
- func (p Picker) AppendItems(items []Item) Picker
- func (p Picker) Count() int
- func (p Picker) Filter() string
- func (p Picker) Highlighted() (Item, bool)
- func (p Picker) SetTheme(t theme.Theme) Picker
- func (p Picker) TotalCount() int
- func (p Picker) Update(msg tea.Msg) (Picker, tea.Cmd)
- func (p Picker) View() string
- func (p Picker) WithFilter(s string) Picker
- func (p Picker) WithItems(items []Item) Picker
- func (p Picker) WithMatcher(m Matcher) Picker
- func (p Picker) WithPlaceholder(s string) Picker
- func (p Picker) WithPreview(f PreviewFunc) Picker
- func (p Picker) WithSize(w, h int) Picker
- func (p Picker) WithTitle(s string) Picker
- type PreviewFunc
- type SelectMsg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Score ¶
Score evaluates the fuzzy match of query against target. Returns 0 if query is not a subsequence of target. Higher = better match.
func SubsequenceMatcher ¶
SubsequenceMatcher scores items by subsequence match with bonuses for start-of-string, word-boundary, and consecutive runs. Returns 0 if query chars don't all appear in order.
Types ¶
type Item ¶
type Item struct {
Title string // primary label
Subtitle string // optional secondary label, dimmed
Group string // optional group label, used by matchers
Value any // opaque payload returned in SelectMsg
}
Item is one row.
type Matcher ¶
Matcher returns a score for it against query. Zero score drops the item; higher scores rank earlier.
type Picker ¶
type Picker struct {
// contains filtered or unexported fields
}
Picker is the model.
func (Picker) AppendItems ¶
AppendItems streams new items into the picker, preserving the cursor.
func (Picker) Highlighted ¶
Highlighted returns the currently highlighted item (if any).
func (Picker) SetTheme ¶ added in v0.38.0
SetTheme swaps the palette used for the border, title, input, and highlighted match row. Next View() picks up the new colors.
func (Picker) TotalCount ¶
TotalCount returns the number of items in the picker, before filtering.
func (Picker) Update ¶
Update routes key events. It returns a tea.Cmd carrying SelectMsg or CancelMsg when those events occur.
func (Picker) WithFilter ¶
WithFilter presets the filter text.
func (Picker) WithMatcher ¶
WithMatcher replaces the matching function.
func (Picker) WithPlaceholder ¶
WithPlaceholder sets the input placeholder.
func (Picker) WithPreview ¶
func (p Picker) WithPreview(f PreviewFunc) Picker
WithPreview wires a preview renderer. If set and the picker is wide enough, the right half shows preview content for the highlighted item.
type PreviewFunc ¶
PreviewFunc renders preview content for the highlighted item. Return "" to skip the preview pane for that item.