keymap

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package keymap provides user-configurable key bindings for revdiff. It maps key names (as returned by bubbletea's KeyMsg.String()) to action names.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidAction

func IsValidAction(a Action) bool

IsValidAction returns true if the action name is recognized.

Types

type Action

type Action string

Action represents a named action that a key can trigger.

const (
	ActionDown             Action = "down"
	ActionUp               Action = "up"
	ActionPageDown         Action = "page_down"
	ActionPageUp           Action = "page_up"
	ActionHalfPageDown     Action = "half_page_down"
	ActionHalfPageUp       Action = "half_page_up"
	ActionHome             Action = "home"
	ActionEnd              Action = "end"
	ActionScrollLeft       Action = "scroll_left"
	ActionScrollRight      Action = "scroll_right"
	ActionNextItem         Action = "next_item"
	ActionPrevItem         Action = "prev_item"
	ActionNextHunk         Action = "next_hunk"
	ActionPrevHunk         Action = "prev_hunk"
	ActionTogglePane       Action = "toggle_pane"
	ActionFocusTree        Action = "focus_tree"
	ActionFocusDiff        Action = "focus_diff"
	ActionSearch           Action = "search"
	ActionConfirm          Action = "confirm"
	ActionAnnotateFile     Action = "annotate_file"
	ActionDeleteAnnotation Action = "delete_annotation"
	ActionAnnotList        Action = "annot_list"
	ActionToggleCollapsed  Action = "toggle_collapsed"
	ActionToggleWrap       Action = "toggle_wrap"
	ActionToggleTree       Action = "toggle_tree"
	ActionToggleLineNums   Action = "toggle_line_numbers"
	ActionToggleHunk       Action = "toggle_hunk"
	ActionFilter           Action = "filter"
	ActionQuit             Action = "quit"
	ActionDiscardQuit      Action = "discard_quit"
	ActionHelp             Action = "help"
	ActionDismiss          Action = "dismiss"
)

action constants for all mappable actions.

type HelpEntry

type HelpEntry struct {
	Action      Action
	Description string
	Section     string
}

HelpEntry describes a single action for the help overlay.

type HelpEntryWithKeys

type HelpEntryWithKeys struct {
	Action      Action
	Description string
	Keys        string // formatted as "key1 / key2"
}

HelpEntryWithKeys is a help entry with the effective key bindings attached.

type HelpSection

type HelpSection struct {
	Name    string
	Entries []HelpEntryWithKeys
}

HelpSection groups help entries under a section heading.

type Keymap

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

Keymap maps key names to actions. Keys are stored as the string returned by bubbletea's tea.KeyMsg.String().

func Default

func Default() *Keymap

Default returns a Keymap with all default bindings.

func Load

func Load(path string) (*Keymap, error)

Load reads a keybindings file from path and returns a Keymap with defaults overridden by the file contents. Returns error if the file cannot be opened or parsed.

func LoadOrDefault

func LoadOrDefault(path string) *Keymap

LoadOrDefault loads keybindings from path if the file exists, otherwise returns Default(). Parse errors are logged as warnings and Default() is returned.

func (*Keymap) Bind

func (km *Keymap) Bind(key string, action Action)

Bind maps a key to an action, overriding any previous binding for that key.

func (*Keymap) Dump

func (km *Keymap) Dump(w io.Writer)

Dump writes the effective bindings to w in the keybindings file format, grouped by section with # comments. Output can be loaded back with Parse.

func (*Keymap) HelpSections

func (km *Keymap) HelpSections() []HelpSection

HelpSections returns grouped help entries with effective key bindings. Actions with no bound keys are omitted.

func (*Keymap) KeysFor

func (km *Keymap) KeysFor(action Action) []string

KeysFor returns all keys bound to the given action, sorted alphabetically.

func (*Keymap) Resolve

func (km *Keymap) Resolve(key string) Action

Resolve returns the action bound to the given key, or empty Action if unbound.

func (*Keymap) Unbind

func (km *Keymap) Unbind(key string)

Unbind removes the binding for the given key. No-op if key is not bound.

Jump to

Keyboard shortcuts

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