Documentation
¶
Overview ¶
Package keymap provides a configurable key-dispatch system for grut.
The keymap loads keybinding definitions from TOML scheme files (embedded or user-supplied), tracks the current input mode (global/panel/input), and dispatches key events to action strings. It does NOT execute actions — the root model's Update() maps action strings to actual behaviour.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WarnConflicts ¶
func WarnConflicts(bindings []Binding)
WarnConflicts detects conflicts in bindings and logs each one as a warning via slog.
Types ¶
type Binding ¶
type Binding struct {
Key string // Key combination, e.g. "ctrl+c", "j", "ctrl+b z"
Action string // Internal action identifier, e.g. "quit", "cursor_down"
Context string // Panel name for context-specific bindings, or "" for all
Description string // Human-readable description
Mode KeyMode // When this binding is active
}
Binding describes a single key binding with its mode, context, and action.
func LoadScheme ¶
LoadScheme loads key bindings from a built-in scheme name or a filesystem path. Built-in names: "default", "classic", "vim". Any name containing "/" or "\" is treated as a file path.
type Conflict ¶
Conflict describes a duplicate key+mode+context combination where multiple actions are bound to the same key.
func DetectConflicts ¶
DetectConflicts finds duplicate key+mode+context combinations in bindings. A conflict exists when two or more bindings share the same key, mode, and context but map to different actions.
type Keymap ¶
type Keymap struct {
// contains filtered or unexported fields
}
Keymap holds all key bindings and dispatches key events to action strings.
func NewKeymap ¶
NewKeymap creates a Keymap by loading the named scheme. The scheme can be "default", "classic", "vim", or a filesystem path.
func NewKeymapFromBindings ¶
NewKeymapFromBindings creates a Keymap from a pre-loaded set of bindings.
func (*Keymap) ClearPending ¶
func (km *Keymap) ClearPending()
ClearPending discards any buffered multi-key prefix.
func (*Keymap) CurrentMode ¶
CurrentMode returns the active key mode.
func (*Keymap) Dispatch ¶
Dispatch finds the action for a key press in the given context. Returns the action string and whether a binding was found.
Dispatch priority:
- Global bindings (always checked)
- Context-specific panel/input bindings (matching context)
- General panel/input bindings (empty context)
func (*Keymap) HasPending ¶
HasPending reports whether a multi-key prefix is buffered.