keymap

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package keymap turns key events into named actions.

Keeping key knowledge out of the UI is what lets the whole mapping be tested without a terminal. There is one map, Default; nothing overrides it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PadLabel

func PadLabel(label string, width int) string

PadLabel right-pads a label to the given display width.

Types

type Action

type Action int

Action is something the user asked for, independent of how they asked.

const (
	// ActionNone means the event is not a command; the widget should handle
	// it as ordinary input.
	ActionNone Action = iota

	// Running.
	ActionRun
	ActionRunAll
	ActionCancel
	// ActionCopyOrCancel is Ctrl+C, whose meaning depends on whether text is
	// selected. The keymap cannot see that state, so it names the ambiguity
	// instead of guessing.
	ActionCopyOrCancel

	// Cursor movement. These are the one place ⌘ and Ctrl differ: on macOS
	// ⌘← goes to the start of a line while Ctrl← moves by word.
	ActionWordLeft
	ActionWordRight
	ActionSelectWordLeft
	ActionSelectWordRight
	ActionLineStart
	ActionLineEnd
	ActionSelectLineStart
	ActionSelectLineEnd
	ActionDeleteWordLeft
	ActionDeleteToLineStart

	// Editing.
	ActionCopy
	ActionCut
	ActionPaste
	ActionSelectAll
	ActionToggleComment
	ActionDuplicateLine
	ActionDeleteLine

	// Navigation and panes.
	ActionNextPane
	ActionPrevPane
	ActionToggleSidebar
	ActionRefreshSchema
	ActionUseSchema

	ActionComplete
	ActionFind
	ActionFindNext
	ActionFindPrev
	ActionSearchHistory
	// ActionCycleTab moves through the tabs of whichever pane has focus.
	ActionCycleTab
	// ActionInspect shows the selected result row read down the page instead
	// of across it.
	ActionInspect
	// ActionSortColumn orders the results by the selected column, and back
	// again — the third press restores the order the server sent.
	ActionSortColumn
	// ActionCopyRow puts the row under the grid's cursor on the clipboard,
	// tab separated, so it lands in a spreadsheet as columns.
	ActionCopyRow

	// ActionCopyResult puts the whole result on the clipboard, in a format
	// chosen when the key is pressed.
	ActionCopyResult
	// ActionSwitchDataSource opens the datasource list: connect to another
	// one, or add, edit and delete entries.
	ActionSwitchDataSource

	// Application.
	ActionHelp
	ActionQuit
)

func AllActions

func AllActions() []Action

AllActions lists every bindable action in help-screen order.

func (Action) Describe

func (a Action) Describe() string

Describe returns the help-screen text for the action.

func (Action) Reserved

func (a Action) Reserved() bool

Reserved reports whether the action names a feature that is not built yet.

func (Action) String

func (a Action) String() string

type Binding

type Binding struct {
	Key  tcell.Key
	Rune rune // only meaningful when Key is tcell.KeyRune
	Mods tcell.ModMask
}

Binding is one key combination in a canonical form.

Canonical means: a combination that can be written as a rune is stored as KeyRune plus a lower-case rune, never as one of tcell's control-code constants. Terminals disagree about which form they send — an extended terminal reports Ctrl+A as KeyRune 'a' with ModCtrl, a legacy one as KeyCtrlA — and folding both into one shape is what lets a single registration serve every terminal.

func (Binding) Event

func (b Binding) Event() *tcell.EventKey

Event renders the binding as an event, which is how tests reach Lookup without constructing a tcell.EventKey by hand.

func (Binding) Label

func (b Binding) Label(mac bool) string

Label renders the binding for display. On macOS the familiar glyphs are used, since that is what DataGrip and every other Mac application shows.

type Map

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

Map resolves key events to actions.

func Default

func Default() *Map

Default is the key map. There is one.

func (*Map) Bindings

func (m *Map) Bindings(a Action) []Binding

Bindings returns the bindings for an action, most idiomatic first.

func (*Map) DisplayBindings

func (m *Map) DisplayBindings(a Action) []Binding

DisplayBindings returns an action's bindings with duplicates collapsed, for the help screen.

Some bindings exist only so a key keeps working on terminals that cannot report it properly — Ctrl+J standing in for Ctrl+Enter, for instance. They render identically to the binding they stand for, and listing both makes the table look broken. They stay bound; they just stop being advertised.

func (*Map) Lookup

func (m *Map) Lookup(ev *tcell.EventKey) Action

Lookup returns the action bound to the event, or ActionNone.

Jump to

Keyboard shortcuts

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