Documentation
¶
Overview ¶
Package picker is the searchable list behind the command palette and every other picker of the UI (functions, sheets, named ranges, macros, themes, files to import): a search field on top, results below with matched characters highlighted, in the manner of fzf. It knows the UI only through Host.
Index ¶
- Constants
- type Host
- type Item
- type Match
- type Picker
- func (p *Picker) Answer(title string) (tea.Cmd, bool)
- func (p *Picker) Changed()
- func (p *Picker) Close()
- func (p *Picker) Cursor() (int, int)
- func (p *Picker) Indicator() string
- func (p *Picker) Key(k tea.KeyPressMsg) tea.Cmd
- func (p *Picker) Layout() []overlay.Box
- func (p *Picker) Mouse(e overlay.MouseEvent) tea.Cmd
- func (p *Picker) Selected() *Item
- func (p *Picker) Shown() []Match
- func (p *Picker) Status() (string, string)
- func (p *Picker) Title() string
Constants ¶
const FirstRow = 3
FirstRow is the box's first result row, under the top border, the search field and a separator.
const ID = "picker"
ID identifies the picker's box in mouse events.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Host ¶
type Host interface {
Theme() *theme.Theme
Size() (width, height int)
// Line is the shared edit line the search is typed in.
Line() *lineedit.Line
// Close closes the open overlay.
Close()
// RecordAnswer tells a macro recording the answer to the question of
// the command that opened the picker, or that it was cancelled.
RecordAnswer(answer string, cancelled bool)
}
Host is what a picker needs of the UI.
type Item ¶
type Item struct {
Title string // e.g. "Save as"
Name int // bytes of Title that are searched, e.g. just "SUM" of "SUM(value, ...)"
Detail string // a dimmed second column, also searched, e.g. the menu path
Key string // shortcut, shown as a key chip
Desc string // what it does, for the status line
Off bool // unavailable right now
Pick func() tea.Cmd
// Swatch, when set, is drawn before the title as it is, styled: a
// sample of a color or a line.
Swatch string
}
Item is one row of a picker.
type Match ¶
Match is an item that matches the search, with the matched byte offsets in its title and detail.
type Picker ¶
type Picker struct {
overlay.List
// Action is what Enter does, for the key hints ("run" by default).
Action string
Items []Item
// Narrow, when set, sees the search first and can narrow the items by
// it, as "dark" does the themes: it returns the rest of the search,
// matched against the kept items' titles only, and which items to
// keep, or a nil keep to search every item as usual.
Narrow func(query string) (rest string, keep func(*Item) bool)
// Enter, when set, gets the first look at Enter with the search text,
// e.g. to take a typed path; it reports whether it handled it.
Enter func(query string) (tea.Cmd, bool)
// Answers marks a picker that is the question of a command that
// changes the workbook: a recording keeps the title picked as the
// command's answer, and scripts answer it with a title.
Answers bool
// At, when set, is where the box's top-left corner goes, as a
// dropdown opens under its cell; the box stays on screen. Pickers
// open centered under the menu bar otherwise.
At *[2]int
// contains filtered or unexported fields
}
Picker is a searchable list in a box: a search field on top, results below with matched characters highlighted, and the highlighted result's description on the status line. The search is edited in the host's edit line with the usual line-editing keys.
func New ¶
New returns a picker of items titled title, at most maxW columns wide inside its frame, with the edit line cleared for the search.
func (*Picker) Answer ¶
Answer picks the item titled title (in any case), as a script answers the picker's question, and reports whether there was one.
func (*Picker) Changed ¶
func (p *Picker) Changed()
Changed filters the items by the search. Best matches come first; ties keep menu order.
func (*Picker) Close ¶
func (p *Picker) Close()
Close closes the picker without picking, which cancels the question it asks.