menu

package
v0.1.35 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package menu provides the filterable overlay list behind the two discovery surfaces the controls spec requires: the command palette (`:`) and the contextual actions menu (`a` / right-click). They differ only in what fills them, so they share one implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	// Label is what the user reads, e.g. "Delete topic".
	Label string
	// Key is the direct binding shown alongside the label, e.g. "d". Empty when
	// the action has no direct binding, which is how most entries look.
	Key string
	// Desc is optional secondary text.
	Desc string
	// Disabled marks an action the user may not perform right now.
	Disabled bool
	// Reason explains a disabled entry: a permission denial, read-only mode, or
	// a missing capability. Required when Disabled is set.
	Reason string
	// Destructive renders the entry in the danger style.
	Destructive bool
	// Mnemonic is the letter that runs this entry directly while the menu is
	// open. Assigned automatically from the label when the menu opens; the
	// first unused letter wins.
	Mnemonic rune
	// Run builds the command to execute, and is called ONLY when the entry is
	// chosen. It is a builder rather than a tea.Cmd because building an entry
	// must never have a side effect: the menu is constructed in order to be
	// displayed, and an eager `Run: k.openCreateForm()` would open the form
	// behind the menu on every render.
	Run func() tea.Cmd
}

Entry is one row of a menu. Disabled entries are still listed — the spec requires the user to see that an action exists and why they cannot use it.

type Model

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

Model is the overlay itself.

func New

func New() *Model

func (*Model) Active

func (m *Model) Active() bool

Active reports whether the menu is capturing input.

func (*Model) Close

func (m *Model) Close()

Close hides the menu without running anything.

func (*Model) Open

func (m *Model) Open(title string, entries []Entry)

Open shows the contextual actions menu: entries carry mnemonics, so `a` then a letter runs an action in two keystrokes.

func (*Model) OpenFilter

func (m *Model) OpenFilter(title string, entries []Entry)

OpenFilter shows a search-first menu — the command palette. Every printable key filters; there are no mnemonics, because you cannot type "ksqlDB" on a surface where `k` and `s` run things.

func (*Model) SelectedEntry

func (m *Model) SelectedEntry() (Entry, bool)

SelectedEntry exposes the highlighted entry, for tests.

func (*Model) SetDimensions

func (m *Model) SetDimensions(w, h int)

SetDimensions sizes the overlay.

func (*Model) Update

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

Update handles input while the menu is open. It returns true when it consumed the message, which is how the caller honours the overlay's input precedence.

func (*Model) View

func (m *Model) View() string

View renders the overlay. An empty string means it is closed.

Every row is rendered to exactly innerWidth cells, selected or not. Sizing the selected row separately is what made the highlight wrap onto a second line, overrun the right border, and misalign the key column against the other rows.

Jump to

Keyboard shortcuts

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