Skip to main content

Key

Struct Key 

Source
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: Modifiers

Implementations§

Source§

impl Key

Source

pub const fn new(code: KeyCode) -> Key

Source

pub const fn with(code: KeyCode, modifiers: Modifiers) -> Key

A key and the modifiers held with it.

Source

pub const fn ctrl(c: char) -> Key

Source

pub const fn char(c: char) -> Key

Source

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.

Source

pub const fn exact(self) -> Key

This key as a terminal that tells every key apart reports it (the kitty keyboard protocol): it matches a binding for itself only. A Session with the protocol on reads keys so, and a test marks them to stand for such a terminal.

Source

pub const fn is_exact(&self) -> bool

Whether the key came from a terminal that tells every key apart.

Source

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.

Source

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.

Source

pub fn matches_any<'a>( &self, bindings: impl IntoIterator<Item = &'a Key>, ) -> bool

Whether this key fires a binding for any of bindings.

Source

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.

Source

pub fn is_interrupt(&self) -> bool

Ctrl+C: the event loop ends every component with Outcome::Interrupted on it.

Trait Implementations§

Source§

impl Clone for Key

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Key

Source§

impl Debug for Key

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Key

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Key

Source§

impl From<Key> for Event

Source§

fn from(key: Key) -> Event

Converts to this type from the input type.
Source§

impl Hash for Key

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Key

Source§

fn eq(&self, other: &Key) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.