Struct TerminalKey

Source
pub struct TerminalKey { /* private fields */ }
Expand description

A key pressed in a terminal.

It’s important to remember when setting up keybindings and building a TUI that some terminals represent several keypresses the same way by default, while others are capable of precisely representing what keys the user actually pressed, such as when using something like crossterm::event::PushKeyboardEnhancementFlags or when running in Windows terminal.

For example, if you’re using crossterm::event::KeyCode then you’ll likely run into the following in a Unix terminal:

  • <C-M> will sometimes be represented as <Enter>
  • <C-I> will sometimes be represented as <Tab>
  • <C-?> will sometimes be represented as <BackSpace>
  • <C-@> will sometimes be represented as <C-Space>
  • <C-[> will sometimes be represented as <Esc>
  • <C-\> will sometimes be represented as <C-4>
  • <C-]> will sometimes be represented as <C-5>
  • <C-^> will sometimes be represented as <C-6>
  • <C-_> will sometimes be represented as <C-7>

You can avoid getting bit by differences between terminals by mapping all of these to the same action for consistency.

Additionally, some modifier keys can’t be expressed by default: <S-Enter> or <C-Enter> cannot always be represented. If you map those, make sure you also provide alternatives!

Implementations§

Source§

impl TerminalKey

Source

pub fn get_literal_char(&self) -> Option<char>

Return this key’s representation as a single codepoint, if it exists.

Trait Implementations§

Source§

impl Clone for TerminalKey

Source§

fn clone(&self) -> TerminalKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TerminalKey

Source§

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

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

impl Display for TerminalKey

Source§

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

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

impl From<KeyCode> for TerminalKey

Source§

fn from(code: KeyCode) -> Self

Converts to this type from the input type.
Source§

impl From<KeyEvent> for TerminalKey

Source§

fn from(ke: KeyEvent) -> Self

Converts to this type from the input type.
Source§

impl FromStr for TerminalKey

Source§

type Err = MacroError

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

fn from_str(input: &str) -> Result<Self, Self::Err>

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

impl Hash for TerminalKey

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<I: ApplicationInfo> InputBindings<TerminalKey, InputStep<I>> for EmacsBindings<I>

Source§

fn setup(&self, machine: &mut EmacsMachine<TerminalKey, I>)

Add new bindings to a ModalMachine instance.
Source§

impl<I: ApplicationInfo> InputBindings<TerminalKey, InputStep<I>> for VimBindings<I>

Source§

fn setup(&self, machine: &mut VimMachine<TerminalKey, I>)

Add new bindings to a ModalMachine instance.
Source§

impl InputKey for TerminalKey

Source§

type Error = MacroError

The error type returned when parsing a macro string fails.
Source§

fn decompose(&mut self) -> Option<Self>

If the input that produced this key could possibly represent two keys, split out the first key. Read more
Source§

fn from_macro_str(input: &str) -> Result<Vec<Self>, MacroError>

Parse a string representing a series of keypresses.
Source§

fn get_char(&self) -> Option<char>

Return this key’s representation as a single, printable codepoint, if it exists.
Source§

impl InputKeyClass<TerminalKey> for CommonKeyClass

Source§

fn memberships(ke: &TerminalKey) -> Vec<Self>

Return the classes that the InputKey belongs to. Read more
Source§

impl<I: ApplicationInfo> InputKeyState<TerminalKey, CommonKeyClass> for EmacsState<I>

Source§

fn event( &mut self, ev: &EdgeEvent<TerminalKey, CommonKeyClass>, ke: &TerminalKey, )

Update the context as needed after a Key has matched an EdgeEvent.
Source§

fn get_cursor_indicator(&self) -> Option<char>

Return a character to show at the current cursor position.
Source§

impl<I: ApplicationInfo> InputKeyState<TerminalKey, CommonKeyClass> for VimState<I>

Source§

fn event( &mut self, ev: &EdgeEvent<TerminalKey, CommonKeyClass>, ke: &TerminalKey, )

Update the context as needed after a Key has matched an EdgeEvent.
Source§

fn get_cursor_indicator(&self) -> Option<char>

Return a character to show at the current cursor position.
Source§

impl<I: ApplicationInfo> ModeKeys<TerminalKey, Action<I>, EmacsState<I>> for EmacsMode

Source§

fn unmapped( &self, ke: &TerminalKey, ctx: &mut EmacsState<I>, ) -> (Vec<Action<I>>, Option<Self>)

Return the default behaviour for the current mode when the given key is unmapped. Read more
Source§

impl<I: ApplicationInfo> ModeKeys<TerminalKey, Action<I>, VimState<I>> for VimMode

Source§

fn unmapped( &self, ke: &TerminalKey, ctx: &mut VimState<I>, ) -> (Vec<Action<I>>, Option<Self>)

Return the default behaviour for the current mode when the given key is unmapped. Read more
Source§

impl PartialEq for TerminalKey

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<I: ApplicationInfo> Step<TerminalKey> for InputStep<I>

Source§

type A = Action<I>

The type of output action produced after input.
Source§

type State = EmacsState<I>

A context object for managing state that accompanies actions.
Source§

type M = EmacsMode

The possible modes for mapping keys.
Source§

type Class = CommonKeyClass

Classes of input keys.
Source§

type Sequence = RepeatType

A key type for identifying tracked action sequences which can be later repeated.
Source§

fn is_unmapped(&self) -> bool

Indicates whether this step should be treated as if it’s an unmapped key, and reset to the root of the current mode.
Source§

fn fallthrough(&self) -> Option<Self::M>

Indicate a mode to fall through to when there is no other valid edge. Read more
Source§

fn step(&self, ctx: &mut EmacsState<I>) -> (Vec<Action<I>>, Option<Self::M>)

Called once the bindings that lead to this Step have been pressed. Read more
Source§

impl<I: ApplicationInfo> Step<TerminalKey> for InputStep<I>

Source§

type A = Action<I>

The type of output action produced after input.
Source§

type State = VimState<I>

A context object for managing state that accompanies actions.
Source§

type Class = CommonKeyClass

Classes of input keys.
Source§

type M = VimMode

The possible modes for mapping keys.
Source§

type Sequence = RepeatType

A key type for identifying tracked action sequences which can be later repeated.
Source§

fn is_unmapped(&self) -> bool

Indicates whether this step should be treated as if it’s an unmapped key, and reset to the root of the current mode.
Source§

fn fallthrough(&self) -> Option<Self::M>

Indicate a mode to fall through to when there is no other valid edge. Read more
Source§

fn step(&self, ctx: &mut VimState<I>) -> (Vec<Action<I>>, Option<Self::M>)

Called once the bindings that lead to this Step have been pressed. Read more
Source§

impl Copy for TerminalKey

Source§

impl Eq for TerminalKey

Source§

impl StructuralPartialEq for TerminalKey

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

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

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

impl<T> Any for T
where T: Any,

Source§

impl<T> CloneAny for T
where T: Any + Clone,

Source§

impl<T> CloneAnySend for T
where T: Any + Send + Clone,

Source§

impl<T> CloneAnySendSync for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> CloneAnySync for T
where T: Any + Sync + Clone,