pub struct Binding {
pub key: KeyCode,
pub modifiers: Option<KeyModifiers>,
pub display: String,
pub description: String,
pub visible: bool,
}Expand description
A single key binding with display text and description.
Fields§
§key: KeyCodeThe key code for matching.
modifiers: Option<KeyModifiers>Optional modifier (Ctrl, Alt, Shift).
display: StringDisplay text shown in help bar (e.g., “q”, “Ctrl+S”, “↑”).
description: StringDescription of what this binding does.
visible: boolWhether to show in help bar.
Implementations§
Source§impl Binding
impl Binding
Sourcepub fn matches(&self, key: &KeyEvent) -> bool
pub fn matches(&self, key: &KeyEvent) -> bool
Returns true if key is a press of this binding’s registered chord.
This is the dispatch primitive that mirrors bubbletea’s
key.Matches: a KeyEvent matches when it is a press (releases
and repeats never match), its KeyCode equals Binding::key, and
its modifiers satisfy Binding::modifiers:
modifiers: Nonerequires that no modifiers are held (so a plainqbinding does not fire onCtrl+q).modifiers: Some(mods)requires that at least every modifier inmodsis held, matching the lenient semantics ofContext::key_mod.
§Examples
use slt::{Event, KeyCode, KeyMap, KeyModifiers};
let km = KeyMap::new().bind('q', "Quit");
let binding = &km.bindings[0];
let Event::Key(quit) = Event::key_char('q') else { unreachable!() };
assert!(binding.matches(&quit));
// A plain binding ignores modified presses of the same key.
let Event::Key(ctrl_q) = Event::key_ctrl('q') else { unreachable!() };
assert!(!binding.matches(&ctrl_q));
// A different key never matches.
let Event::Key(other) = Event::key_char('x') else { unreachable!() };
assert!(!binding.matches(&other));
// Modifier bindings use `contains` semantics.
let save = KeyMap::new().bind_mod('s', KeyModifiers::CONTROL, "Save");
let Event::Key(ctrl_s) =
Event::key_mod(KeyCode::Char('s'), KeyModifiers::CONTROL)
else {
unreachable!()
};
assert!(save.bindings[0].matches(&ctrl_s));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Binding
impl RefUnwindSafe for Binding
impl Send for Binding
impl Sync for Binding
impl Unpin for Binding
impl UnsafeUnpin for Binding
impl UnwindSafe for Binding
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
Mutably borrows from an owned value. Read more