Documentation
¶
Overview ¶
Package keys maps raw input onto semantic actions and footer hint legends for viewkit applications.
Index ¶
- func Activate(key string) bool
- func DisplayName(key string) string
- func Keys() []string
- func Normalize(key string) string
- func Register(key, name string, s Scheme)
- func Resolve(binds map[string]string, key string) (target string, ok bool)
- func Use(s Scheme)
- type Action
- type Binding
- type Hint
- type Map
- type Scheme
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Activate ¶ added in v0.2.0
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 DisplayName ¶ added in v0.0.1
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
Normalize canonicalizes a key name for comparison, folding case and trimming surrounding whitespace.
func Register ¶ added in v0.0.1
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 — deliberately unlike the first-wins glyph/panels/deck registries, where overriding is a collision. Safe for concurrent use.
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 ¶
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 ¶
DisplayGlyph returns Glyph, or the key names joined with "/" when no glyph is set.
type Hint ¶ added in v0.2.0
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
MapFor builds a Map from the active scheme's bindings for the given actions, replacing the sc := Cur(); NewMap(sc.Binding(...), ...) boilerplate.
func NewMap ¶
NewMap builds a Map from bindings. When two bindings share an action or a key, the later one wins.
func (*Map) Action ¶
Action returns the action bound to the given input key, reporting whether the key is mapped.
func (*Map) 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 ¶
HintLabeled is Hint with the binding's label replaced by label.
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
Named returns the scheme registered under key. When key is not registered it returns Default() and false.
func (Scheme) EditorBindings ¶ added in v0.1.6
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 ¶
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
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.