keys

package
v0.0.0-...-6b1cd05 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActionDescription

func ActionDescription(a Action) string

ActionDescription returns a human-readable description for an action.

func ScopeLabel

func ScopeLabel(s Scope) string

ScopeLabel returns a human-readable label for a scope.

Types

type Action

type Action string

Action represents a user action that can be triggered by a keybinding.

const (
	// Global actions
	ActionQuit           Action = "quit"
	ActionForceQuit      Action = "force_quit"
	ActionHelp           Action = "help"
	ActionFocusLeft      Action = "focus_left"
	ActionFocusRight     Action = "focus_right"
	ActionFocusToggle    Action = "focus_toggle"
	ActionViewAgent      Action = "view_agent"
	ActionViewDiff       Action = "view_diff"
	ActionViewPlan       Action = "view_plan"
	ActionNewSession     Action = "new_session"
	ActionStopSession    Action = "stop_session"
	ActionRestartSession Action = "restart_session"

	// Sidebar actions
	ActionMoveUp        Action = "move_up"
	ActionMoveDown      Action = "move_down"
	ActionSelect        Action = "select"
	ActionToggle        Action = "toggle"
	ActionDeleteSession Action = "delete_session"

	// Agent view actions
	ActionEnterInput Action = "enter_input"
	ActionExitInput  Action = "exit_input"

	// Diff view actions
	ActionOpenEditor       Action = "open_editor"
	ActionOpenEditorAtLine Action = "open_editor_at_line"
	ActionPageDown         Action = "page_down"
	ActionPageUp           Action = "page_up"
	ActionCursorUp         Action = "cursor_up"
	ActionCursorDown       Action = "cursor_down"
	ActionJumpTop          Action = "jump_top"
	ActionJumpBottom       Action = "jump_bottom"
	ActionSearchStart      Action = "search_start"
	ActionSearchNext       Action = "search_next"
	ActionSearchPrev       Action = "search_prev"
	ActionComment          Action = "comment"
	ActionSendComments     Action = "send_comments"
	ActionRefreshDiff      Action = "refresh_diff"
	ActionColumnLeft       Action = "column_left"
	ActionColumnRight      Action = "column_right"
	ActionEditComment      Action = "edit_comment"

	// Terminal split
	ActionOpenTerminal        Action = "open_terminal"
	ActionToggleTerminalFocus Action = "toggle_terminal_focus"

	// Mouse toggle
	ActionToggleMouse Action = "toggle_mouse"

	// No-op
	ActionNone Action = ""
)

type Binding

type Binding struct {
	Key    string `json:"key"`
	Action Action `json:"action"`
	Scope  Scope  `json:"scope"`
}

Binding maps a key string to an action within a scope.

type Handler

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

Handler resolves key messages to actions based on the current scope. Supports leader key sequences for accessing application commands.

func NewHandler

func NewHandler(km *KeyMap) *Handler

NewHandler creates a new key handler with Space as the default leader key.

func NewHandlerWithLeader

func NewHandlerWithLeader(km *KeyMap, leaderKey string) *Handler

NewHandlerWithLeader creates a handler with a custom leader key. Pass an empty string to disable leader key functionality.

func (*Handler) Handle

func (h *Handler) Handle(msg tea.KeyMsg, scope Scope) Action

Handle resolves a key message to an action. Supports leader key sequences: if leader key is pressed, waits for next key and tries to resolve "<leader>+<next_key>" binding first.

func (*Handler) InLeaderMode

func (h *Handler) InLeaderMode() bool

InLeaderMode returns true if we're waiting for the next key in a leader sequence. This can be used to show visual feedback (e.g., in status bar).

func (*Handler) KeyMap

func (h *Handler) KeyMap() *KeyMap

KeyMap returns the underlying key map.

func (*Handler) LeaderKey

func (h *Handler) LeaderKey() string

LeaderKey returns the current leader key.

func (*Handler) SetKeyMap

func (h *Handler) SetKeyMap(km *KeyMap)

SetKeyMap replaces the key map.

func (*Handler) SetLeaderKey

func (h *Handler) SetLeaderKey(key string)

SetLeaderKey updates the leader key. Pass empty string to disable leader functionality.

type KeyMap

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

KeyMap holds all keybindings grouped by scope.

func DefaultKeyMap

func DefaultKeyMap() *KeyMap

DefaultKeyMap returns the default keybindings.

func Merge

func Merge(defaults, user *KeyMap) *KeyMap

Merge creates a new KeyMap with user bindings overriding defaults. User bindings with the same scope+key replace the default.

func NewKeyMap

func NewKeyMap(bindings []Binding) *KeyMap

NewKeyMap creates a KeyMap from a list of bindings.

func (*KeyMap) Bindings

func (km *KeyMap) Bindings() []Binding

Bindings returns all bindings.

func (*KeyMap) BindingsForScope

func (km *KeyMap) BindingsForScope(scope Scope) []Binding

BindingsForScope returns all bindings for a given scope.

func (*KeyMap) Resolve

func (km *KeyMap) Resolve(key string, scope Scope) Action

Resolve returns the action for a key in the given scope. It checks the specific scope first, then falls back to global.

type Scope

type Scope string

Scope defines where a keybinding is active.

const (
	ScopeGlobal    Scope = "global"
	ScopeSidebar   Scope = "sidebar"
	ScopeAgentView Scope = "agent_view"
	ScopeDiffView  Scope = "diff_view"
	ScopePlanView  Scope = "plan_view"
)

Jump to

Keyboard shortcuts

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