Struct crokey::KeyCombination

source ·
pub struct KeyCombination {
    pub codes: OneToThree<KeyCode>,
    pub modifiers: KeyModifiers,
}
Expand description

A Key combination wraps from one to three standard keys with optional modifiers (ctrl, alt, shift).

Fields§

§codes: OneToThree<KeyCode>§modifiers: KeyModifiers

Implementations§

source§

impl KeyCombination

source

pub fn new<C: Into<OneToThree<KeyCode>>>( codes: C, modifiers: KeyModifiers ) -> Self

Create a new KeyCombination from one to three keycodes and a set of modifiers

source

pub const fn one_key(code: KeyCode, modifiers: KeyModifiers) -> Self

Create a new KeyCombination from one keycode and a set of modifiers

source

pub const fn is_ansi_compatible(self) -> bool

Ansi terminals don’t manage key press/release/repeat, so they don’t allow to determine whether 2 keys are pressed at the same time. This means a combination involving several key codes can’t be distiguished from a sequences of combinations involving a single key code. For this reason, only combinations involving a single key code are considered “ansi compatible”

source

pub fn normalized(self) -> Self

Return a normailzed version of the combination.

Fix the case of the code to uppercase if the shift modifier is present. Add the SHIFT modifier if one code is uppercase.

This allows direct comparisons with the fields of crossterm::event::KeyEvent whose code is uppercase when the shift modifier is present. And supports the case where the modifier isn’t mentionned but the key is uppercase.

source

pub const fn as_letter(self) -> Option<char>

return the raw char if the combination is a letter event

Trait Implementations§

source§

impl Clone for KeyCombination

source§

fn clone(&self) -> KeyCombination

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for KeyCombination

source§

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

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

impl<'de> Deserialize<'de> for KeyCombination

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for KeyCombination

source§

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

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

impl From<KeyCode> for KeyCombination

source§

fn from(key_code: KeyCode) -> Self

Converts to this type from the input type.
source§

impl From<KeyEvent> for KeyCombination

source§

fn from(key_event: KeyEvent) -> Self

Converts to this type from the input type.
source§

impl FromStr for KeyCombination

§

type Err = ParseKeyError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, ParseKeyError>

Parses a string s to return a value of this type. Read more
source§

impl Hash for KeyCombination

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 Into<KeyEvent> for KeyCombination

source§

fn into(self) -> KeyEvent

Converts this type into the (usually inferred) input type.
source§

impl PartialEq for KeyCombination

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<&[KeyEvent]> for KeyCombination

source§

fn try_from(key_events: &[KeyEvent]) -> Result<Self, Self::Error>

Try to create a KeyCombination from a slice of key events, will fail if and only if the slice is empty.

§

type Error = &'static str

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

impl Copy for KeyCombination

source§

impl Eq for KeyCombination

source§

impl StructuralPartialEq for KeyCombination

Auto Trait Implementations§

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> 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> ToOwned for T
where T: Clone,

§

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§

default 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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,