keymap

package
v0.5.57 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package keymap provides the global, user-mappable key-binding dictionary: stable action names ("window.close") mapped to key + modifier combinations, with JSON persistence so applications (and a future Settings UI) can override the defaults at startup.

Spec string format — modifier + key names joined by '+', order-insensitive, case-insensitive:

"Escape"                  plain key
"Ctrl+W"                  modifier + key
"Ctrl+Shift+F"            multiple modifiers

Modifier names: Ctrl/Control, Shift, Alt/Option, Meta/Cmd/Super/Win. Key names cover the mobilegles Keycode set (see keyNames).

Index

Constants

View Source
const (
	ActionExitFullscreen = "app.exit-fullscreen"
	ActionCloseWindow    = "window.close"
	ActionCloseTab       = "window.close-tab"
	ActionFocusSearch    = "view.focus-search"
)

Seed action names. Applications register additional actions with Default().MustBind / Bind.

Variables

This section is empty.

Functions

func FormatSpec

func FormatSpec(key platform.KeyCode, mods platform.Modifiers) string

FormatSpec renders key+mods back into canonical spec form ("Ctrl+Shift+Escape") — used for persistence and Settings display.

func LoadOverrides

func LoadOverrides(m *Map)

LoadOverrides applies the first keymap file found (MEUI_KEYMAP=<path> or ./keymap.json) onto m. Missing files are not an error — the seed defaults simply stand. Load errors (bad JSON, bad specs) are logged, not fatal.

func ParseSpec

func ParseSpec(spec string) (platform.KeyCode, platform.Modifiers, error)

ParseSpec parses a spec string like "Ctrl+Shift+Escape" into a key plus modifier set. Tokens are case-insensitive; order is ignored.

Types

type Binding

type Binding struct {
	Action string
	Key    platform.KeyCode
	Mods   platform.Modifiers
}

Binding is one action bound to one key + modifier combination.

type Map

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

Map is an ordered set of bindings; the first binding matching a key event wins. Actions may share a key — MatchAll returns every match in order so handlers can skip contextual actions (exit-fullscreen only fires while fullscreen, then the next match, window.close, applies).

func Default

func Default() *Map

Default returns the process-wide key map: the seed bindings with any overrides from the keymap file applied (MEUI_KEYMAP=<path>, or ./keymap.json when present).

func Defaults

func Defaults() *Map

Defaults returns a Map with the framework seed bindings. Esc is bound to both exit-fullscreen and window.close: handlers try actions in order (MatchAll) and skip contextual ones that don't apply, so plain Esc closes a window while Esc in fullscreen only leaves fullscreen — matching the legacy hardcoded behavior.

func New

func New() *Map

New returns an empty Map.

func (*Map) ActionSpec

func (m *Map) ActionSpec(action string) (string, bool)

ActionSpec returns the spec string currently bound to action ("Ctrl+W") — for Settings UI display.

func (*Map) All

func (m *Map) All() []Binding

All snapshots the bindings.

func (*Map) Bind

func (m *Map) Bind(action, spec string) error

Bind parses spec ("Ctrl+Shift+Escape") and binds it to action, replacing any existing binding for the same action.

func (*Map) Load

func (m *Map) Load(path string) (int, error)

Load reads path and applies every entry onto m as an override (rebinding the action's key). Unknown actions are still bound — the file may define bindings for application-specific actions. Returns the number of bindings applied.

func (*Map) Match

func (m *Map) Match(key platform.KeyCode, mods platform.Modifiers) (string, bool)

Match returns the action of the FIRST binding matching key+mods.

func (*Map) MatchAll

func (m *Map) MatchAll(key platform.KeyCode, mods platform.Modifiers) []string

MatchAll returns every matching action in binding order — handlers walk it when actions are contextual (exit-fullscreen fires only while fullscreen, then window.close applies to the same key).

func (*Map) MustBind

func (m *Map) MustBind(action, spec string) *Map

MustBind is Bind for seed tables; a bad spec is a programming error.

func (*Map) Save

func (m *Map) Save(path string) error

Save writes the map's bindings to path (JSON, stable ordering).

func (*Map) Unbind

func (m *Map) Unbind(action string)

Unbind removes the binding for action. No-op when absent.

Jump to

Keyboard shortcuts

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