pub struct Input {
pub key: Key,
pub ctrl: bool,
pub alt: bool,
pub shift: bool,
}Expand description
Backend-agnostic key input type.
When crossterm, termion, termwiz features are enabled, converting respective key input types into this
Input type is defined.
use ratatui_textarea::{TextArea, Input, Key};
use crossterm::event::{Event, read};
let event = read().unwrap();
// `Input::from` can convert backend-native event into `Input`
let input = Input::from(event.clone());
// or `Into::into`
let input: Input = event.clone().into();
// Conversion from `KeyEvent` value is also available
if let Event::Key(key) = event {
let input = Input::from(key);
}Creating Input instance directly can cause backend-agnostic input as follows.
use ratatui_textarea::{TextArea, Input, Key};
let mut textarea = TextArea::default();
// Input Ctrl+A
textarea.input(Input {
key: Key::Char('a'),
ctrl: true,
alt: false,
shift: false,
});Fields§
§key: KeyTyped key.
ctrl: boolCtrl modifier key. true means Ctrl key was pressed.
alt: boolAlt modifier key. true means Alt key was pressed.
shift: boolShift modifier key. true means Shift key was pressed.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Input
impl<'de> Deserialize<'de> for Input
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Input
Source§impl From<InputEvent> for Input
Available on crate feature termwiz only.
impl From<InputEvent> for Input
termwiz only.Source§fn from(input: InputEvent) -> Self
fn from(input: InputEvent) -> Self
Convert ratatui_termwiz::termwiz::input::InputEvent into Input.
Source§impl From<Key> for Input
Available on crate feature termion only.
impl From<Key> for Input
termion only.Source§fn from(key: KeyEvent) -> Self
fn from(key: KeyEvent) -> Self
Convert ratatui_termion::termion::event::Key into Input.
termion does not provide a way to get Shift key’s state. Instead termion passes key inputs
as-is. For example, when ‘Shift + A’ is pressed with US keyboard, termion passes
ratatui_termion::termion::event::Key::Char('A'). We cannot know how the ‘A’ character was
input.
So the shift field of the returned Input instance is always false except for
combinations with arrow keys. For example,
ratatui_termion::termion::event::Key::Char('A') is converted to Input { key: Key::Char('A'), shift: false, .. }.
Source§impl From<MouseEvent> for Input
Available on crate feature crossterm only.
impl From<MouseEvent> for Input
crossterm only.Source§fn from(mouse: MouseEvent) -> Self
fn from(mouse: MouseEvent) -> Self
Convert ratatui_crossterm::crossterm::event::MouseEvent into Input.
Source§impl From<MouseEvent> for Input
Available on crate feature termion only.
impl From<MouseEvent> for Input
termion only.Source§fn from(mouse: MouseEvent) -> Self
fn from(mouse: MouseEvent) -> Self
Convert ratatui_termion::termion::event::MouseEvent into Input.
Source§impl From<MouseEvent> for Input
Available on crate feature termwiz only.
impl From<MouseEvent> for Input
termwiz only.Source§fn from(mouse: MouseEvent) -> Self
fn from(mouse: MouseEvent) -> Self
Convert ratatui_termwiz::termwiz::input::MouseEvent into Input.
Source§impl From<PixelMouseEvent> for Input
Available on crate feature termwiz only.
impl From<PixelMouseEvent> for Input
termwiz only.Source§fn from(mouse: PixelMouseEvent) -> Self
fn from(mouse: PixelMouseEvent) -> Self
Convert ratatui_termwiz::termwiz::input::PixelMouseEvent into Input.
impl StructuralPartialEq for Input
Auto Trait Implementations§
impl Freeze for Input
impl RefUnwindSafe for Input
impl Send for Input
impl Sync for Input
impl Unpin for Input
impl UnsafeUnpin for Input
impl UnwindSafe for Input
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more