keys

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 3 Imported by: 4 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 keys maps raw input onto semantic actions and footer hint legends for viewkit applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Activate added in v0.2.0

func Activate(key string) bool

Activate looks up the named scheme and makes it active, replacing the Named-then-Use two-step. It reports whether key was registered; the active scheme is left unchanged when it was not.

func ControlKeys added in v0.1.6

func ControlKeys(in []string) []string

ControlKeys filters a binding's keys down to the multi-rune ones ("tab", "ctrl+s", "esc"), dropping single characters. Text-entry contexts use it so ordinary typing is not swallowed by navigation bindings.

func DisplayName added in v0.0.1

func DisplayName(key string) string

DisplayName returns the human-readable name registered for key, or key itself when it is not registered.

func Keys added in v0.0.1

func Keys() []string

Keys returns the registered scheme keys in registration order, "default" first.

func Normalize added in v0.1.6

func Normalize(key string) string

Normalize canonicalizes a key name for comparison, folding case and trimming surrounding whitespace.

func Register added in v0.0.1

func Register(key, name string, s Scheme)

Register adds scheme s to the registry under key with the given display name. A later call with the same key replaces the earlier name and scheme in place, so apps can override the built-in entry. Safe for concurrent use.

func Resolve added in v0.1.6

func Resolve(binds map[string]string, key string) (target string, ok bool)

Resolve looks key up in a user-supplied hotkey table and returns the target it is bound to. Lookup is case- and whitespace-insensitive on both sides, so a table written by hand still matches. Keys bound to a blank target report ok=false.

func Use

func Use(s Scheme)

Use makes s the active scheme. Safe to call while other goroutines read Cur.

Types

type Action

type Action string

Action names a user intent ("confirm", "nav.up") independent of the keys bound to it. Views match on Actions so key layout can change per scheme.

const (
	Up        Action = "nav.up"
	Down      Action = "nav.down"
	Left      Action = "nav.left"
	Right     Action = "nav.right"
	Confirm   Action = "confirm"
	Cancel    Action = "cancel"
	Quit      Action = "quit"
	FocusNext Action = "focus.next"
	FocusPrev Action = "focus.prev"
	Inc       Action = "inc"
	Dec       Action = "dec"
	Erase     Action = "erase"
	PageUp    Action = "page.up"
	PageDown  Action = "page.down"
	Open      Action = "open"
	Reload    Action = "reload"

	// Complete accepts the suggestion a text field is showing. It shares tab
	// with FocusNext: a host that binds both resolves the conflict by build
	// order, and one that binds Complete alone gets tab-to-accept for free.
	Complete     Action = "complete"
	CompleteNext Action = "complete.next"
	CompletePrev Action = "complete.prev"
)

Standard actions every scheme is expected to bind: cursor and focus movement, confirm/cancel/quit, value adjustment (Inc/Dec), paging, and the text-completion trio. Default binds all of them.

type Binding

type Binding struct {
	Keys   []string
	Action Action
	Glyph  string
	Label  string
}

Binding ties one or more key names to an Action. Glyph and Label are optional footer-hint text: Glyph is the display form of the keys and Label describes the effect.

func (Binding) DisplayGlyph

func (b Binding) DisplayGlyph() string

DisplayGlyph returns Glyph, or the key names joined with "/" when no glyph is set.

func (Binding) WithGlyph

func (b Binding) WithGlyph(glyph string) Binding

WithGlyph returns a copy of b with Glyph set to glyph.

func (Binding) WithLabel

func (b Binding) WithLabel(label string) Binding

WithLabel returns a copy of b with Label set to label.

type Hint added in v0.2.0

type Hint struct {
	Key   string
	Label string
}

Hint is one footer-legend entry: the key (or context name) on the left and its label (or value) on the right.

type Map

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

Map indexes a fixed set of bindings both by key name (for input dispatch) and by Action (for hints and Has checks). Build one with NewMap or MapFor.

func MapFor added in v0.2.0

func MapFor(actions ...Action) *Map

MapFor builds a Map from the active scheme's bindings for the given actions, replacing the sc := Cur(); NewMap(sc.Binding(...), ...) boilerplate.

func NewMap

func NewMap(bindings ...Binding) *Map

NewMap builds a Map from bindings. When two bindings share an action or a key, the later one wins.

func (*Map) Action

func (m *Map) Action(input string) (a Action, ok bool)

Action returns the action bound to the given input key, reporting whether the key is mapped.

func (*Map) Has

func (m *Map) Has(a Action) bool

Has reports whether the map carries a binding for a.

func (*Map) Hint

func (m *Map) Hint(a Action) Hint

Hint returns the footer hint for a: the binding's display glyph paired with its label. An unbound action yields an empty Hint.

func (*Map) HintLabeled

func (m *Map) HintLabeled(a Action, label string) Hint

HintLabeled is Hint with the binding's label replaced by label.

func (*Map) Hints

func (m *Map) Hints(actions ...Action) []Hint

Hints returns footer hints for the given actions in order, keeping only bindings that carry an explicit Glyph; unbound or glyph-less actions are skipped rather than falling back to raw key names.

type Scheme

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

Scheme is a complete keymap: one Binding per Action. Schemes are treated as immutable; With and WithDefaults return modified copies.

func Cur

func Cur() Scheme

Cur returns the active scheme by value (matching theme.Cur); a later Use does not change a Scheme already returned.

func Default

func Default() Scheme

Default returns the built-in scheme: arrow keys doubled with vi-style h/j/k/l, enter/space to confirm, esc to cancel, ctrl+c to quit, tab focus cycling, and bracket/plus/minus value adjustment.

func Named added in v0.0.1

func Named(key string) (Scheme, bool)

Named returns the scheme registered under key. When key is not registered it returns Default() and false.

func (Scheme) Binding

func (s Scheme) Binding(a Action) Binding

Binding returns the binding for a, or the zero Binding when a is unbound.

func (Scheme) EditorBindings added in v0.1.6

func (s Scheme) EditorBindings(actions ...Action) []Binding

EditorBindings resolves actions against s and strips their single-character keys, yielding the subset safe to bind while a text field has focus. Actions left with no keys are omitted.

func (Scheme) With

func (s Scheme) With(overrides ...Binding) Scheme

With returns a copy of s with overrides applied, each replacing any existing binding for its action. s itself is not modified.

func (Scheme) WithDefaults added in v0.2.0

func (s Scheme) WithDefaults(defaults ...Binding) Scheme

WithDefaults fills every action missing from s (or bound without keys) from defaults; bindings already in s win. Use it to graft app-specific actions onto a user-selected scheme instead of falling back at each lookup.

Jump to

Keyboard shortcuts

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