pub struct Key {
pub code: KeyCode,
pub modifiers: Modifiers,
/* private fields */
}Expand description
A key press.
Two keys are equal when their code and modifiers are. How the terminal
reported one changes only which bindings it matches:
a terminal without the kitty keyboard protocol (a legacy terminal) sends
one byte for Tab and for Ctrl+I, so its Tab could be either key, while a
key marked exact is only itself.
Fields§
§code: KeyCode§modifiers: ModifiersImplementations§
Source§impl Key
impl Key
pub const fn new(code: KeyCode) -> Key
Sourcepub const fn with(code: KeyCode, modifiers: Modifiers) -> Key
pub const fn with(code: KeyCode, modifiers: Modifiers) -> Key
A key and the modifiers held with it.
pub const fn ctrl(c: char) -> Key
pub const fn char(c: char) -> Key
Sourcepub fn parse(text: &str) -> Option<Key>
pub fn parse(text: &str) -> Option<Key>
Parse a key name such as enter, ctrl+c, shift+tab, pagedown,
f5 or a single character. Case does not matter for names. The
comma key is , or comma (ctrl+comma), the name a list of key
names can hold without quotes; the other punctuation keys have names
too, for where the character is awkward (a key list, a TOML string,
ctrl+minus): see punctuation. A key named so is the character,
and shows as it (equals is =).
A name means the key: ctrl+i is Ctrl+I, not Tab, although a legacy
terminal sends the two alike; matches is what lets
a Tab from such a terminal fire a ctrl+i binding.
Sourcepub const fn is_exact(&self) -> bool
pub const fn is_exact(&self) -> bool
Whether the key came from a terminal that tells every key apart.
Sourcepub fn legacy(self) -> Key
pub fn legacy(self) -> Key
This key as a legacy terminal sends it: Ctrl+I arrives as Tab,
Ctrl+M as Enter, Ctrl+[ as Esc, Ctrl+\ ] ^ _ as Ctrl+4 to 7, Ctrl+@
as Ctrl+Space, and Ctrl+Shift with a letter as Ctrl and the letter.
Any other key arrives as itself. The result is not
exact.
Sourcepub fn matches(&self, binding: &Key) -> bool
pub fn matches(&self, binding: &Key) -> bool
Whether this key, as read, fires a binding for binding. A key
fires a binding for itself. One from a legacy terminal also fires a
binding for any key that terminal sends alike (see
legacy): its Tab fires tab or ctrl+i; and its
Ctrl+H, which some terminals send for Backspace, fires ctrl+h or
backspace. An exact key fires only its own.
Sourcepub fn matches_any<'a>(
&self,
bindings: impl IntoIterator<Item = &'a Key>,
) -> bool
pub fn matches_any<'a>( &self, bindings: impl IntoIterator<Item = &'a Key>, ) -> bool
Whether this key fires a binding for any of bindings.
Sourcepub fn pick<'a>(
&self,
sets: impl IntoIterator<Item = &'a [Key]>,
) -> Option<usize>
pub fn pick<'a>( &self, sets: impl IntoIterator<Item = &'a [Key]>, ) -> Option<usize>
Which of sets (each the keys of one binding) this key fires: the
first that has it exactly, else the first it
matches. A Tab from a legacy terminal picks a
tab binding over an earlier ctrl+i one.
Sourcepub fn is_interrupt(&self) -> bool
pub fn is_interrupt(&self) -> bool
Ctrl+C: the event loop ends every component with
Outcome::Interrupted on it.
Trait Implementations§
impl Copy for Key
impl Eq for Key
Auto Trait Implementations§
impl Freeze for Key
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnsafeUnpin for Key
impl UnwindSafe for Key
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,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more