Skip to content
API reference

keys

Import
import * as api from "@fungi.computer/nacre/keys";
Kind Export Description
type alias ShellChord One physical chord parsed from a Whistle binding such as alt+left.
type alias KeyEventFacts Keyboard facts shared by DOM events and terminal adapters.
type alias LeaderKey One key offered after the leader chord, with the command it runs.
type alias ShellKeyHost The shell host operations the key dispatcher reads.
function parseChord() Parse one single-chord binding. Sequences (including <leader>x) and unknown modifiers return null; they are never matched as one chord.
function chordMatches() Whether one key event is exactly this chord.
function leaderKeys() The single-keystroke <leader>x rows, first binding per key.
function leaderKeyMatches() Whether one key event (after the leader) selects this leader key.
function installShellKeys() Dispatch the active view’s single-chord bindings from the shell document. Text entry is a mode: while an input is focused only Ctrl/Cmd chords fire, so Alt-arrows keep their word-navigation meaning.

ShellChordtype alias

Section titled “ShellChord”
Signature
type ShellChord = Readonly<{
key: string;
alt: boolean;
ctrl: boolean;
meta: boolean;
shift: boolean;
}>;

One physical chord parsed from a Whistle binding such as alt+left.


KeyEventFactstype alias

Section titled “KeyEventFacts”
Signature
type KeyEventFacts = Pick<
KeyboardEvent,
"altKey" | "ctrlKey" | "key" | "metaKey" | "shiftKey"
>;

Keyboard facts shared by DOM events and terminal adapters.


LeaderKeytype alias

Section titled “LeaderKey”
Signature
type LeaderKey = WhistleBindingProjection &
Readonly<{
key: string;
}>;

One key offered after the leader chord, with the command it runs.


ShellKeyHosttype alias

Section titled “ShellKeyHost”
Signature
type ShellKeyHost = Readonly<{
active: () => WhistleSnapshot;
subscribe: (listener) => () => void;
execute: (commandId, input) => Promise<WhistleExecutionOutcome>;
}>;

The shell host operations the key dispatcher reads.

parseChord()function

Section titled “parseChord()”
Signature
function parseChord(
binding,
mac,
): Readonly<{
key: string;
alt: boolean;
ctrl: boolean;
meta: boolean;
shift: boolean;
}> | null;

Parse one single-chord binding. Sequences (including <leader>x) and unknown modifiers return null; they are never matched as one chord.

Parameter Type
binding string
mac boolean

| Readonly<{ key: string; alt: boolean; ctrl: boolean; meta: boolean; shift: boolean; }> | null


chordMatches()function

Section titled “chordMatches()”
Signature
function chordMatches(event, chord): boolean;

Whether one key event is exactly this chord.

Parameter Type
event KeyEventFacts
chord ShellChord

boolean


leaderKeys()function

Section titled “leaderKeys()”
Signature
function leaderKeys(active): readonly LeaderKey[];

The single-keystroke <leader>x rows, first binding per key.

Parameter Type
active WhistleSnapshot

readonly LeaderKey[]


leaderKeyMatches()function

Section titled “leaderKeyMatches()”
Signature
function leaderKeyMatches(event, key): boolean;

Whether one key event (after the leader) selects this leader key.

Parameter Type
event Pick<KeyboardEvent, "altKey" | "ctrlKey" | "key" | "metaKey">
key string

boolean


installShellKeys()function

Section titled “installShellKeys()”
Signature
function installShellKeys(root, host, mac): () => void;

Dispatch the active view’s single-chord bindings from the shell document. Text entry is a mode: while an input is focused only Ctrl/Cmd chords fire, so Alt-arrows keep their word-navigation meaning.

Parameter Type
root HTMLElement
host ShellKeyHost
mac boolean

() => void