pub struct KeyChord {
pub key: KeyKind,
pub mods: KeyMods,
}Expand description
Canonical, stack-allocated representation of one chord.
Copy so call sites can pass it freely without lifetime
gymnastics; Hash + Eq so it works as a HashMap key in
the keymap trie. Memory: 8 bytes (1-byte mod bitfield + 1-byte
discriminant + a 4-byte char or 1-byte SpecialKey, padded).
Parse one chord with str::parse (FromStr), a sequence with
parse_chord_sequence; Display writes the canonical notation.
§Examples
use lattice_protocol::{ChordParseError, KeyChord, KeyKind, KeyMods, SpecialKey};
let chord: KeyChord = "<C-S-Tab>".parse().unwrap();
assert_eq!(chord.key, KeyKind::Special(SpecialKey::Tab));
assert_eq!(chord.mods, KeyMods::CTRL | KeyMods::SHIFT);
assert_eq!(chord.to_string(), "<C-S-Tab>");
// `<` and a bare space are escaped when printed.
assert_eq!(KeyChord::char('<').to_string(), "<lt>");
assert_eq!(KeyChord::char(' ').to_string(), "<Space>");
// `FromStr` wants exactly one chord.
assert!(matches!("ab".parse::<KeyChord>(), Err(ChordParseError::BodyTooLong { .. })));Fields§
§key: KeyKindWhich key was pressed.
mods: KeyModsModifiers held with it. For a letter, Shift is encoded in the case of
KeyKind::Char instead, so this carries no SHIFT bit.
Implementations§
Source§impl KeyChord
impl KeyChord
Sourcepub const fn new(key: KeyKind, mods: KeyMods) -> Self
pub const fn new(key: KeyKind, mods: KeyMods) -> Self
Build directly from kind + mods. Useful for tests +
internal callers; production callers go through the
renderer-specific adapter (lattice_ui_tui::chord::from_event
for the TUI, the analogous function in the future GPUI
adapter).
Sourcepub const fn ctrl(c: char) -> Self
pub const fn ctrl(c: char) -> Self
Ctrl-modified character. Letter case is normalised by the
caller; convention is lowercase (<C-c>, not <C-C>).
Sourcepub const fn special(k: SpecialKey) -> Self
pub const fn special(k: SpecialKey) -> Self
Special key with no modifiers.
Trait Implementations§
impl Copy for KeyChord
impl Eq for KeyChord
impl StructuralPartialEq for KeyChord
Auto Trait Implementations§
impl Freeze for KeyChord
impl RefUnwindSafe for KeyChord
impl Send for KeyChord
impl Sync for KeyChord
impl Unpin for KeyChord
impl UnsafeUnpin for KeyChord
impl UnwindSafe for KeyChord
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.