palette

package
v0.0.35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
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

func SplitQuery(q string) (name, args string)

SplitQuery separates the command word from its arguments.

Types

type Action

type Action int

Action is what a keypress asked the app to do.

const (
	// ActionNone means the palette handled the key itself.
	ActionNone Action = iota
	// ActionRun means Enter was pressed: execute Line().
	ActionRun
	// ActionCancel means Escape was pressed: close without running.
	ActionCancel
)

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 New

func New(r theme.Roles) Model

func (Model) ArgMatches added in v0.0.29

func (m Model) ArgMatches() []Arg

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) IsVisible

func (m Model) IsVisible() bool

func (Model) Line added in v0.0.29

func (m Model) Line() string

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

func (m Model) Matches() []Item

Matches returns the currently filtered items, for tests and for callers that want to know whether anything matched.

func (*Model) Open

func (m *Model) Open()

Open shows the palette with an empty query.

func (Model) Query

func (m Model) Query() string

Query returns the raw typed text, command word and arguments together.

func (Model) Selected

func (m Model) Selected() (Item, bool)

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

func (m Model) SelectedArg() (Arg, bool)

SelectedArg returns the highlighted argument value, if the palette is listing values and the partial argument matched any.

func (*Model) SetItems

func (m *Model) SetItems(items []Item)

SetItems replaces the command list. The app calls this with its registry.

func (*Model) SetRoles added in v0.0.29

func (m *Model) SetRoles(r theme.Roles)

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".

func (Model) View

func (m Model) View() string

View renders the overlay. Every line is exactly Width cells, so the caller can place it without the frame shearing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL