keys

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 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 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

func Keys added in v0.0.1

func Keys() []string

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)

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
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"
)

type Binding

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

func (Binding) DisplayGlyph

func (b Binding) DisplayGlyph() string

func (Binding) WithGlyph

func (b Binding) WithGlyph(glyph string) Binding

func (Binding) WithLabel

func (b Binding) WithLabel(label string) Binding

type Map

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

func NewMap

func NewMap(bindings ...Binding) *Map

func (*Map) Action

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

func (*Map) Has

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

func (*Map) Hint

func (m *Map) Hint(a Action) [2]string

func (*Map) HintLabeled

func (m *Map) HintLabeled(a Action, label string) [2]string

func (*Map) Hints

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

type Scheme

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

func Cur

func Cur() Scheme

func Default

func Default() Scheme

func Named added in v0.0.1

func Named(key string) (Scheme, bool)

func (Scheme) Binding

func (s Scheme) Binding(a Action) Binding

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

Jump to

Keyboard shortcuts

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