palette

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 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.

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 Query().
	ActionRun
	// ActionCancel means Escape was pressed: close without running.
	ActionCancel
)

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
}

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

func (*Model) SetItems

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

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

func (Model) Update

func (m Model) Update(msg tea.KeyPressMsg) (Model, Action)

Update handles a keypress while the palette owns input.

Navigation is arrows and ctrl+n/ctrl+p 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