slash

package
v1.11.0 Latest Latest
Warning

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

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

Documentation

Overview

Package slash renders the autocomplete suggestion panel that pops up when the user types "/" at the start of the input. It is NOT part of the focus stack — the input keeps focus while the panel is visible; the panel is a passive renderer plus a tiny state machine for the highlighted row and the "Esc dismissed this typing session" flag.

The App owns one *Panel for the lifetime of the program and drives it through Match (on every keystroke), MoveSel (on Up/Down when the panel is visible), Complete (on Tab), and Dismiss / Reset (on Esc and after-submit).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Name string
	Desc string
}

Command is one entry in the suggestion catalog. Name includes the leading "/". Builtin commands ship with the binary; skill entries are added at runtime from Controller.Skills().

func Catalog

func Catalog(ctrl ui.Controller) []Command

Catalog returns the merged builtin + skills catalog. ctrl may be nil — pre-Attach state — in which case only builtins are returned.

func Match

func Match(input string, catalog []Command) []Command

Match returns ALL catalog entries whose name has the trimmed, lowercased input as a prefix, in catalog order. Empty / non-"/" input returns nil so the caller can collapse the panel.

The full list is returned so navigation (MoveSel/Complete) can reach every match; View renders only a maxSuggestions-sized window over it.

type Panel

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

Panel holds the suggestion-overlay's state:

  • selected: the highlighted row, clamped to the current match list each render (a shrinking list could otherwise leave selected dangling past the end).
  • dismissed: true after Esc, until the input drops back to "" (so re-typing "/" reopens the panel naturally).

func New

func New() *Panel

New returns an empty panel. Cheap; safe to create at App construction time.

func (*Panel) Complete

func (p *Panel) Complete(input string, catalog []Command) string

Complete returns the full name of the currently highlighted suggestion (or "" when no matches). The App uses this to replace the input's value on Tab.

func (*Panel) Dismiss

func (p *Panel) Dismiss()

Dismiss hides the panel until the user clears the input back below "/". Bound to Esc in the App when no overlay is open.

func (*Panel) MoveSel

func (p *Panel) MoveSel(input string, catalog []Command, delta int) bool

MoveSel shifts the highlighted row by delta (+1 / -1). Clamps to the bounds of the current match list. Returns true when a move happened so the App can swallow the key event.

func (*Panel) Reset

func (p *Panel) Reset()

Reset clears the dismissed flag — called when the user submits (so the next /-prefixed input shows suggestions again) and when the user blanks the input box.

func (*Panel) Selected

func (p *Panel) Selected() int

Selected returns the highlighted index (clamped if the match list shrank since the user last navigated).

func (*Panel) View

func (p *Panel) View(input string, ctrl ui.Controller, width int, th *theme.Theme) string

View renders the panel as a bordered box, or "" when not visible. width is the column count to render within; the panel uses a 4-col inner margin so the bordered box sits inside the App's layout slot.

func (*Panel) Visible

func (p *Panel) Visible(input string, overlayOpen bool, catalog []Command) bool

Visible reports whether the panel should be drawn for the given input + overlay state. The App passes overlayOpen=true whenever any modal Focusable is on top — slash suggestions stay hidden behind overlays where the input box itself is inert.

Jump to

Keyboard shortcuts

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