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 ¶
- type Entry
- type Model
- func (m *Model) Active() bool
- func (m *Model) Close()
- func (m *Model) Open(title string, entries []Entry)
- func (m *Model) OpenFilter(title string, entries []Entry)
- func (m *Model) SelectedEntry() (Entry, bool)
- func (m *Model) SetDimensions(w, h int)
- func (m *Model) Update(msg tea.Msg) (tea.Cmd, bool)
- func (m *Model) View() string
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 (*Model) Open ¶
Open shows the contextual actions menu: entries carry mnemonics, so `a` then a letter runs an action in two keystrokes.
func (*Model) OpenFilter ¶
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 ¶
SelectedEntry exposes the highlighted entry, for tests.
func (*Model) SetDimensions ¶
SetDimensions sizes the overlay.
func (*Model) Update ¶
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 ¶
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.