Skip to main content

Module chord

Module chord 

Source
Expand description

Crossterm → KeyChord adapter for the TUI renderer.

Phase 5.4 split: the renderer-neutral chord types (KeyChord, KeyKind, SpecialKey, KeyMods, ChordParseError, parse_chord_sequence, last_chord_token_byte_len, and the FromStr / Display impls) live in lattice_host::chord. This module is the TUI-side adapter that turns a crossterm::KeyEvent into the canonical KeyChord the keymap trie indexes by.

from_event (the canonical crossterm-side entry) lives here as a free function rather than an impl KeyChord method because orphan rules forbid extending a foreign type from this crate. Existing call sites change from KeyChord::from_event(&ev) to chord::from_event(&ev); the re-export below means crate::chord::KeyChord (and every other neutral type) still resolves unchanged.

The future lattice-ui-gpui ships its own analogous gpui_chord::from_event(&GpuiKeyEvent) -> Option<KeyChord> adapter; both renderers feed the same KeyChord into lattice_host’s dispatch.

Structs§

KeyChord
Canonical, stack-allocated representation of one chord.
KeyMods
Modifier bitfield. Copy + Eq + Hash so the whole KeyChord fits in a CPU register.

Enums§

ChordParseError
Parse-side error variants. Detail-level so :bind-style error messages can surface what was wrong.
ChordPattern
One element of a keymap registration path.
KeyKind
What kind of key the chord represents.
SpecialKey
Named special keys. Renderer-neutral; crossterm’s KeyCode::BackTab is normalised away by the TUI adapter (from_crossterm) into Special(Tab) + KeyMods::SHIFT so the trie has one entry for “shift-tab” rather than two ambiguous ones.

Functions§

format_chord
Render a single crossterm key event as canonical chord notation. Returns None for events that have no chord representation. Thin shim over from_event + to_string.
from_event
Normalise a crossterm::KeyEvent into a canonical KeyChord. Returns None for events that have no chord representation (release events on terminals that emit them, modifier-only presses, key codes we don’t recognise).
last_chord_token_byte_len
Number of bytes the last chord token occupies at the end of text, treating it as a sequence of chord tokens (one chord per logical keypress). Used by chord-capture’s backspace handler to remove a whole token instead of a single char.
parse_chord_sequence
Parse a chord-sequence string into the canonical Vec<KeyChord> the keymap trie indexes by.
special_label
Canonical name for a SpecialKey. Round-trips through parse_special. Renderer-neutral text; both the TUI’s format_chord and any future GPUI describe-key renderer use this label.