Documentation
¶
Overview ¶
Package palette is the `:` command overlay: a filtered list of commands with a live query, driven entirely by a caller-supplied item list — and, once a command that offers them is typed, a filtered list of the values its argument can take.
It deliberately knows nothing about what a command does. The app owns the registry and executes; this package owns the query, the filtering, the selection, and the drawing. That split is what lets the registry stay the single source for the palette, the help card, and the keymap without this package importing any of them.
Index ¶
- Constants
- func SplitQuery(q string) (name, args string)
- type Action
- type Arg
- type Item
- type Model
- func (m Model) ArgMatches() []Arg
- func (m *Model) Close()
- func (m Model) IsVisible() bool
- func (m Model) Line() string
- func (m Model) Matches() []Item
- func (m *Model) Open()
- func (m Model) Query() string
- func (m Model) Selected() (Item, bool)
- func (m Model) SelectedArg() (Arg, bool)
- func (m *Model) SetItems(items []Item)
- func (m *Model) SetRoles(r theme.Roles)
- func (m Model) Update(msg tea.KeyPressMsg) (Model, Action)
- func (m Model) View() string
Constants ¶
const Width = 60
Width is the overlay's fixed width in cells (docs/tui-2.0.md, "Composer, modes, and palette"). Fixed rather than responsive because the palette is a reading surface: a 200-column terminal should not stretch a list of short command names across the whole screen.
Variables ¶
This section is empty.
Functions ¶
func SplitQuery ¶
SplitQuery separates the command word from its arguments.
Types ¶
type Arg ¶ added in v0.0.29
type Arg struct {
// Value is what the argument becomes when this row is chosen.
Value string
// Description is the dim note beside it — where a theme lives, say.
Description string
// Current marks the value in use: the theme on screen, say. The list
// opens with it highlighted, so Enter with nothing typed keeps what is
// there rather than switching to whatever is listed first, and its row
// says "current". At most one value should be.
Current bool
}
Arg is one value a command's argument can take, as the palette offers it.
type Item ¶
type Item struct {
// Name is the command word without the leading colon, e.g. "mark-read".
Name string
// Args is the argument shape shown after the name, e.g. "<query>".
// Empty for commands that take none.
Args string
// Description is the one-line explanation shown beside the name.
Description string
// Key is the equivalent key binding, right-aligned so the palette
// teaches the keymap. Empty when the command has no key of its own.
Key string
// Candidates are the values the argument can take. Once the query is
// this command's exact name and a space, the palette lists these instead
// of commands. Nil for a command whose argument is free text or absent,
// which the palette treats exactly as it always has.
Candidates []Arg
}
Item is one command as the palette displays it. The app builds these from its registry; the palette never interprets them beyond matching Name.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the palette overlay.
func (Model) ArgMatches ¶ added in v0.0.29
ArgMatches returns the argument values currently listed, nil while the palette is listing commands.
func (*Model) Close ¶
func (m *Model) Close()
Close hides the palette and drops the query, so reopening never resurrects a half-typed command from last time.
func (Model) Line ¶ added in v0.0.29
Line is the command line Enter asks the app to run. It is the query as typed, except while an argument's values are listed: then it is the command with the highlighted value, so what runs is what the user sees selected, typed out in full or not. With no value matching it is the query again, and the command gets to say what it was given.
func (Model) Matches ¶
Matches returns the currently filtered items, for tests and for callers that want to know whether anything matched.
func (Model) Selected ¶
Selected returns the highlighted item, if the filter matched anything. While an argument's values are listed that is the command they belong to: the highlight is on one of its values, not on another command.
func (Model) SelectedArg ¶ added in v0.0.29
SelectedArg returns the highlighted argument value, if the palette is listing values and the partial argument matched any.
func (*Model) SetRoles ¶ added in v0.0.29
SetRoles supplies the TUI 2.0 semantic palette, replacing the one New was given. There is nothing derived from it to rebuild: View builds its styles from the roles on every call, so the next frame is drawn in these.
func (Model) Update ¶
func (m Model) Update(msg tea.KeyPressMsg) (Model, Action)
Update handles a keypress while the palette owns input.
Navigation is the arrows only — NOT j/k. The handoff specified j/k, but the palette is a text surface: every printable key has to reach the query or commands like ":jump" and ":keymap" could not be typed at all. See docs/tui-2.0.md, "Divergences from the handoff prose".