keymap

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: 6 Imported by: 0

Documentation

Overview

Package keymap manages centralized keyboard shortcut registration, multi-key sequence handling, context-aware binding resolution, and user-configurable key overrides.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyConfig

func ApplyConfig(r *Registry, cfg *Config)

ApplyConfig applies user configuration overrides to the registry.

func RegisterDefaults

func RegisterDefaults(r *Registry)

RegisterDefaults registers all default bindings with the given registry.

Types

type Binding

type Binding struct {
	Key     string // e.g., "tab", "ctrl+s", "g g"
	Command string // Command ID
	Context string // "global", plugin ID, etc.
}

Binding maps a key or key sequence to a command.

func DefaultBindings

func DefaultBindings() []Binding

DefaultBindings returns the default keymap.

type Category

type Category string

Category represents a command category.

const (
	CategoryNavigation Category = "Navigation"
	CategoryActions    Category = "Actions"
	CategoryView       Category = "View"
	CategorySearch     Category = "Search"
	CategorySystem     Category = "System"
)

type Command

type Command struct {
	ID      string
	Name    string
	Handler func() tea.Cmd
	Context string
}

Command represents a registered command handler.

type Config

type Config struct {
	Bindings map[string]string `json:"bindings"` // key -> command ID
}

Config represents user key binding configuration.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads key binding overrides from a JSON file.

type Registry

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

Registry manages key bindings and command dispatch.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new keymap registry.

func (*Registry) AllContexts

func (r *Registry) AllContexts() []string

AllContexts returns all contexts that have bindings.

func (*Registry) BindingsForContext

func (r *Registry) BindingsForContext(context string) []Binding

BindingsForContext returns all bindings for a given context.

func (*Registry) GetCommand

func (r *Registry) GetCommand(id string) (Command, bool)

GetCommand retrieves a command by ID. Returns the command and true if found, or zero value and false otherwise.

func (*Registry) Handle

func (r *Registry) Handle(key tea.KeyMsg, activeContext string) tea.Cmd

Handle dispatches a key event to the appropriate command handler. Returns nil if no matching binding is found.

func (*Registry) HasPending

func (r *Registry) HasPending() bool

HasPending returns true if there's a pending key sequence.

func (*Registry) RegisterBinding

func (r *Registry) RegisterBinding(b Binding)

RegisterBinding adds a key binding.

func (*Registry) RegisterCommand

func (r *Registry) RegisterCommand(cmd Command)

RegisterCommand adds a command to the registry.

func (*Registry) RegisterPluginBinding

func (r *Registry) RegisterPluginBinding(key, command, context string)

RegisterPluginBinding satisfies plugin.BindingRegistrar interface. It converts plugin.Binding to keymap.Binding and registers it.

func (*Registry) ResetPending

func (r *Registry) ResetPending()

ResetPending clears any pending key sequence.

func (*Registry) SetUserOverride

func (r *Registry) SetUserOverride(key, commandID string)

SetUserOverride sets a user-configured key override.

Jump to

Keyboard shortcuts

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