key

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModAlt   = "alt+"
	ModCtrl  = "ctrl+"
	ModShift = "shift+"
)
View Source
const (
	AltEnter = ModAlt + Enter

	CtrlA = ModCtrl + "a"
	CtrlB = ModCtrl + "b"
	CtrlC = ModCtrl + "c"
	CtrlD = ModCtrl + "d"
	CtrlE = ModCtrl + "e"
	CtrlF = ModCtrl + "f"
	CtrlN = ModCtrl + "n"
	CtrlP = ModCtrl + "p"
	CtrlS = ModCtrl + "s"
)
View Source
const (
	N     = "n"
	Down  = "down"
	Enter = "enter"
	Esc   = "esc"
	Left  = "left"
	Right = "right"
	Space = "space"
	Tab   = "tab"
	Up    = "up"
	Y     = "y"
)
View Source
const (
	ShiftDown = ModShift + Down
	ShiftUp   = ModShift + Up
	ShiftTab  = ModShift + Tab
)
View Source
const (
	ArrowsLeftRight     = "←→"
	ArrowsVertical      = "↕"
	ShiftArrowsVertical = ModShift + ArrowsVertical
)

Variables

This section is empty.

Functions

func Inline

func Inline(key, desc string, keyStyle, textStyle lg.Style) (string, bool)

Inline highlights the key inside the description when it is a single-letter suffix.

func Replay added in v0.2.0

func Replay(s string) tea.KeyPressMsg

Replay rebuilds the KeyPressMsg for a binding's key string ("t", "tab", "shift+tab", "ctrl+u", "ctrl+f5"), so replaying a command-palette selection is byte-for-byte the same event pressing the key would raise - key.Matches compares String(), and this reconstructs exactly that. Modifier prefixes strip left to right; the remainder is a named key, a lone rune, or - for a multi-rune name we don't know - an extended key.

Text is set only when unmodified. A KeyPressMsg's String() returns its Text verbatim when present, ignoring the modifier, so setting Text on a modified key would collapse "ctrl+f99" to a bare "f99" and could fire a command bound to that literal. Leaving Text empty lets String() fall through to the modifier-prefixed keystroke form, so an unsupported modified rebind renders as a stub that matches nothing rather than misfiring.

Types

type Hint

type Hint struct {
	Key  string
	Desc string
}

type Registry added in v0.2.0

type Registry map[string]*bkey.Binding

Registry maps stable lower-case names to the owner's binding fields. Values are pointers so Rebind mutates the owner's key map in place; build the registry from the same struct the app reads bindings off. The registry knows nothing about which bindings exist - the owner declares its own key map struct and hands in the pointers.

func (Registry) Names added in v0.2.0

func (r Registry) Names() []string

Names returns every rebindable binding name, sorted. Useful for docs and for validating a config file's keybinding overrides.

func (Registry) Rebind added in v0.2.0

func (r Registry) Rebind(overrides map[string][]string) error

Rebind applies user overrides keyed by binding name (e.g. {"transition": {"x"}}). An empty key slice is ignored so a partial config never silently unbinds an action. The first key becomes the help label; the description is kept. An unknown name is an error rather than a silent no-op, so a typo in a config file is surfaced - and it is checked before anything mutates, so a failed Rebind leaves every binding exactly as it was.

type Renderer

type Renderer struct {
	Styles Styles
	Gap    string
	Prefix *string
	Width  int
	Inline bool
}

func (Renderer) Render

func (r Renderer) Render(hints []Hint) string

type Styles

type Styles struct {
	Key  lg.Style
	Text lg.Style
}

Jump to

Keyboard shortcuts

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