palette

package
v0.74.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package palette implements the command palette UI for fuzzy searching and executing commands, with support for context filtering and keybinding display.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GroupEntriesByLayer

func GroupEntriesByLayer(entries []PaletteEntry) map[Layer][]PaletteEntry

GroupEntriesByLayer groups entries by their layer for display.

func ScoreEntry

func ScoreEntry(entry *PaletteEntry, query string)

ScoreEntry scores a palette entry against a query. Combines scores from multiple fields with weighting.

func SortEntries

func SortEntries(entries []PaletteEntry)

SortEntries sorts entries by score descending, then by layer, then alphabetically.

Types

type CommandSelectedMsg

type CommandSelectedMsg struct {
	CommandID string
	Context   string
}

CommandSelectedMsg is sent when a command is selected from the palette.

type Layer

type Layer int

Layer represents the contextual hierarchy of a command.

const (
	LayerCurrentMode Layer = iota // e.g., "git-diff" specific
	LayerPlugin                   // e.g., "git-status" base
	LayerGlobal                   // Global shortcuts
)

func (Layer) Name

func (l Layer) Name() string

LayerName returns a display name for the layer.

type MatchRange

type MatchRange struct {
	Start int
	End   int
}

MatchRange represents a contiguous range of matched characters.

func FuzzyMatch

func FuzzyMatch(query, target string) (int, []MatchRange)

FuzzyMatch scores how well query matches target string. Returns score (0 = no match) and ranges for highlighting. Scoring:

  • Consecutive matches: bonus per consecutive char
  • Word start matches (after /, _, -, .): large bonus
  • Shorter targets: small bonus

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model is the command palette state.

func New

func New() Model

New creates a new command palette model.

func (Model) Cursor

func (m Model) Cursor() int

Cursor returns the current cursor position.

func (Model) Filtered

func (m Model) Filtered() []PaletteEntry

Filtered returns the currently filtered entries.

func (Model) Init

func (m Model) Init() tea.Cmd

Init initializes the palette (no-op for now).

func (Model) MaxVisible

func (m Model) MaxVisible() int

MaxVisible returns max visible entries.

func (Model) Offset

func (m Model) Offset() int

Offset returns the scroll offset.

func (*Model) Open

func (m *Model) Open(km *keymap.Registry, plugins []plugin.Plugin, activeContext, pluginContext string)

Open prepares the palette for display. Rebuilds entries based on current context.

func (Model) Query

func (m Model) Query() string

Query returns the current search query.

func (Model) SelectedEntry

func (m Model) SelectedEntry() *PaletteEntry

SelectedEntry returns the currently selected entry, if any.

func (*Model) SetSize

func (m *Model) SetSize(width, height int)

SetSize updates the palette dimensions.

func (Model) ShowAllContexts

func (m Model) ShowAllContexts() bool

ShowAllContexts returns whether all contexts mode is active.

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update handles messages for the palette.

func (Model) View

func (m Model) View() string

View renders the command palette.

type PaletteEntry

type PaletteEntry struct {
	Key          string          // Display key(s): "s" or "ctrl+s"
	CommandID    string          // Command ID
	Name         string          // Short name
	Description  string          // Full description
	Category     plugin.Category // Category for grouping
	Context      string          // Source context
	Layer        Layer           // Which layer: CurrentMode, Plugin, Global
	Score        int             // Fuzzy match score (computed during search)
	MatchRanges  []MatchRange    // For highlighting matches in name
	ContextCount int             // Number of contexts this command appears in (for grouped display)
}

PaletteEntry represents a single searchable entry in the command palette.

func BuildEntries

func BuildEntries(km *keymap.Registry, plugins []plugin.Plugin, activeContext, pluginContext string) []PaletteEntry

BuildEntries aggregates commands from keymap bindings and plugin commands. activeContext is the current focus context (e.g., "git-diff"). pluginContext is the base plugin context (e.g., "git-status").

func FilterEntries

func FilterEntries(entries []PaletteEntry, query string) []PaletteEntry

FilterEntries filters and scores entries against a query. Returns entries sorted by relevance.

func FilterEntriesForContext

func FilterEntriesForContext(entries []PaletteEntry, activeContext string) []PaletteEntry

FilterEntriesForContext returns entries for a specific context + global only. This eliminates duplicates since each command appears at most once per context.

func GroupEntriesByCommand

func GroupEntriesByCommand(entries []PaletteEntry) []PaletteEntry

GroupEntriesByCommand groups entries by CommandID and marks context count. Returns one entry per command with ContextCount set for commands in multiple contexts.

Jump to

Keyboard shortcuts

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