keys

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 14 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

Keybinds every legend, palette and menu derives its keys from, bound per context

Index

Constants

View Source
const (
	Global   = "global"
	Panel    = "panel"
	Session  = "session"
	Complete = "complete"
	Search   = "search"
	Confirm  = "confirm"
	Edit     = "edit"
	Capture  = "capture"
	Palette  = "palette"
	Tabs     = "tabs"
	List     = "list"
	Filter   = "filter"
	Detail   = "detail"
	View     = "view"
	Terminal = "terminal"
	Text     = "text"
	Stash    = "stash"
)

Keybinding contexts. The focused window determines which contexts are active. Global bindings are checked last.

View Source
const (
	QuitID    = "quit"
	SuspendID = "suspend"
)

Actions of the window as a whole that cards ask the window for by their id: quitting icebath, and suspending it to the shell, which the window answers by giving the terminal back until fg brings it back

View Source
const Leader = "leader"

Keymap context of the keys pressed after the leader key, whose actions are named for what they fire: leader. and the id of an action or a command

View Source
const LeaderID = "leader"

Action of the leader key itself, pressed before a key of the Leader context, so a terminal that keeps modifier chords for itself still reaches every action through two plain presses

Variables

View Source
var ContextDocs = map[string]string{
	Global:   "everywhere",
	Panel:    "panels",
	Session:  "chats",
	Complete: "suggestions",
	Search:   "search fields",
	Confirm:  "confirmations",
	Edit:     "cell editing",
	Capture:  "key recording",
	Palette:  "command palette",
	Tabs:     "tabs",
	List:     "lists",
	Filter:   "filterable lists",
	Detail:   "detail panes",
	View:     "read mode",
	Terminal: "terminals",
	Text:     "text fields",
	Leader:   "after the leader key",
	Stash:    "messages put aside",
}

ContextDocs describes each context in the keybind editor.

Functions

func AddContext

func AddContext(name, doc string) error

Adds a keymap context the file and the editor know, refusing a taken name

func Cancels

func Cancels(id string) bool

Whether the action stands for the key that closes the keys after the leader doing nothing

func Captured

func Captured(msg tea.KeyPressMsg) (string, bool)

Chord a key press is stored as when captured, an Option typed character as its alt chord and the shifted symbol over the base key

func Chords

func Chords(msg tea.KeyPressMsg) []string

Every canonical chord a key press may stand for, the shifted symbol and the base layout key included

func Format

func Format(chord string) string

Chord as legends and the file spell it, a shifted letter as its capital, other keys by name and the command key as cmd on a Mac

func LeadsTo

func LeadsTo(id string) (string, bool)

Action or command a key after the leader fires, false for an action of no key after the leader and for the two that stand for the leader key itself

func Literal

func Literal(id string) bool

Whether the action stands for the leader pressed twice, which the sheet lists with the leader's own key

func OptionAlt

func OptionAlt(msg tea.KeyPressMsg) bool

Reports whether the press is an Option typed character read as an alt chord

func OptionOn

func OptionOn() bool

Whether Option typed characters read as alt chords

func Pair

func Pair(a, b string) string

Two chords as a pair such as j/k, arrows in reading order, either alone when the other is unbound

func Parse

func Parse(s string) (string, error)

Canonical form of a chord written by a person, such as Alt+Shift+L, G, ctrl+pgdn or alt++

func Press

func Press(chord string) tea.KeyPressMsg

Key press a terminal reports for the chord, a shifted letter carrying its capital as text

func SetOption

func SetOption(on bool)

Reads the characters Option types on a US Mac keyboard as alt chords, or stops doing so

func Unshifted

func Unshifted(msg tea.KeyPressMsg) (tea.KeyPressMsg, bool)

Press of a named key such as backspace without its shift, false for a printable key or one without shift

Types

type Action

type Action struct {
	ID      string
	Context string
	// Word shown beside the key in legends
	Label string
	// One line for the editor
	Doc     string
	Default []string
	// Fires while an overlay holds the input
	Overlay bool
	// Stays out of the palette, for editing and movement keys
	Quiet bool
	// Why the action may not take a chord of the map, empty when it may, such as a key the terminal keeps for itself or another action holds
	// where the action is pressed. Asked each time its keys are set, so the refusal is said where the key is recorded
	Refuse func(m *Map, chord string) string
	// Line of the sheet of the keys after the leader a key of the Leader context is listed on, the last line for none
	Group string
}

Something a key may fire, handled by the manager, the app or the focused card depending on its context

func Leading

func Leading(group, target, label, doc string, chords ...string) Action

Key after the leader: an action of the Leader context firing the action or command of the target id, listed on the line of its group in the sheet of the keys after the leader, the last line for none. Screens declare the keys after the leader of their own actions with it, as the kit declares those of the window manager

func (Action) DocText

func (a Action) DocText() string

One line description of the action in the window's language, the registered line where the language has none

func (Action) LabelText

func (a Action) LabelText() string

Legend word of the action in the window's language, the registered word where the language has none

type ChangedMsg

type ChangedMsg struct{}

Sent to every card once a bind changed, so inputs rebuild the bindings they hold

type Map

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

Keybinds in force, with the registry they are drawn from

func Default

func Default() *Map

Map holding every registered action at its default keys

func (*Map) Action

func (m *Map) Action(id string) (Action, bool)

Action with the id

func (*Map) Actions

func (m *Map) Actions() []Action

Every action in registry order

func (*Map) Add

func (m *Map) Add(id, chord string) error

Adds a chord to the action

func (*Map) After

func (m *Map) After(msg tea.KeyPressMsg) Second

What a key pressed after the leader asks for: the leader again, a key that only closes the keys after the leader, or the actions and commands its keys after the leader fire; nothing for a key none of them holds

func (*Map) AtDefault

func (m *Map) AtDefault(id string) bool

Reports whether the action holds its default keys

func (*Map) Contexts

func (m *Map) Contexts() []string

Contexts in registry order

func (*Map) Display

func (m *Map) Display(id string) string

First chord of the action the terminal can send, formatted for a legend, empty when there is none; spelled once until the keys change. Spelled under the lock the chords are put in place under, so a legend asked for from another goroutine reads them whole and is never kept from before a change

func (*Map) DisplayAll

func (m *Map) DisplayAll(id string) string

Every chord of the action the terminal can send, formatted and space separated

func (*Map) File

func (m *Map) File(changed bool) []byte

The keymap as a file a person edits and keeps: each action under the place it works, with its keys in brackets and, in a comment beside them, what it does and its default keys. Only the actions whose keys differ from their defaults when changed is true, as a keymap is shared with another computer

func (*Map) First

func (m *Map) First(id string) string

First chord bound to the action, empty when it is unbound

func (*Map) Holder

func (m *Map) Holder(id, chord string) string

Id of another action in the same context holding the chord, empty when it is free

func (*Map) InContexts

func (m *Map) InContexts(contexts []string) []Action

Actions of the contexts in registry order, the global ones last

func (*Map) Keys

func (m *Map) Keys(id string) []string

Chords bound to the action, none when it is unbound

func (*Map) Leads

func (m *Map) Leads(msg tea.KeyPressMsg) bool

Whether the key press is the leader key

func (*Map) Lookup

func (m *Map) Lookup(contexts []string, msg tea.KeyPressMsg) []string

Actions bound to the key press by context, a shifted key no chord names looked up as the key alone

func (*Map) Parked

func (m *Map) Parked() map[string][]string

Keys of the actions taken out of the registry that held keys of their own, by action

func (*Map) Read

func (m *Map) Read(file []byte) (int, error)

Takes the keys a keymap file gives the actions it lists, as File writes it or a person edited it: each of them has the keys listed and no others, and every other action keeps its own; the count of the actions whose keys changed. All or nothing: a file that does not read, names an action there is none of, or gives an action keys it can't take changes nothing, and the error says each of what is wrong

func (*Map) Rebind

func (m *Map) Rebind(id, chord string) error

Binds the action to the one chord

func (*Map) Register

func (m *Map) Register(a Action)

Adds an action to the registry at its default keys, replacing one with the same id

func (*Map) Remove

func (m *Map) Remove(id string)

Takes an action out of the registry, such as one of a screen that is gone, keeping the keys it held in place of its defaults for when it comes back

func (*Map) Reset

func (m *Map) Reset(id string) error

Returns the action to its default keys

func (*Map) ResetAll

func (m *Map) ResetAll()

Puts every action back on its default keys

func (*Map) Sendable

func (m *Map) Sendable(id string) []string

Chords of the action the terminal can send

func (*Map) Sequence

func (m *Map) Sequence(id string) string

Keys to press for the action as text names them: the leader's key and then the key after it for a key after the leader, the leader's key alone for the leader pressed twice, the action's own key for any other; empty while one of them is unbound

func (*Map) Sequences

func (m *Map) Sequences(id string) string

Every way to press the action as text names it: the keys of an action space separated as DisplayAll spells them, and the sequences of a key after the leader comma separated, each led by the leader's key; empty while it is unbound

func (*Map) Set

func (m *Map) Set(id string, chords []string) error

Replaces every chord of the action with the given ones, refused when one is held by another action of its context or the action refuses it

func (*Map) SetDefault

func (m *Map) SetDefault(id string, chords []string) error

Changes the keys the action starts with, keeping the keys a person bound in its place and taking the new ones only while it holds the old default; a chord another action of the same context holds is left out

func (*Map) SetShiftApart

func (m *Map) SetShiftApart(on bool)

Records whether the terminal reports ctrl and shift on a letter apart from ctrl alone

func (*Map) ShiftApart

func (m *Map) ShiftApart() bool

Whether the terminal reports modified keys apart, as the kitty keyboard protocol does

func (*Map) Unbind

func (m *Map) Unbind(id string) error

Leaves the action without keys

func (*Map) Unsendable

func (m *Map) Unsendable(chord string) string

Why this terminal cannot send the chord, empty when it can: ctrl and shift on a letter, a modified enter, tab or backspace and the command key all need a terminal reporting modified keys apart, the command key a Mac besides

func (*Map) Version

func (m *Map) Version() uint64

Count of the changes to the actions and their keys so far, so a legend drawn from the map is drawn again only once it moved

type Second

type Second struct {
	// Actions and commands the keys after the leader bound to it fire, the first that applies to the window in hand winning
	Targets []string
	// The leader pressed again, which reaches the window as itself
	Again bool
	// A key that closes the keys after the leader and does nothing more, such as esc
	Cancel bool
}

What a key pressed after the leader asks for

func (Second) Unknown

func (s Second) Unknown() bool

Whether the key asks for nothing the leader knows, which closes the keys after the leader with nothing done

Jump to

Keyboard shortcuts

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