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 tui_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 tui_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>,
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 termwiz::input::InputEvent into Input.
Source§impl From<Key> for Input
Available on crate features termion or tuirs-termion only.
impl From<Key> for Input
termion or tuirs-termion only.Source§fn from(key: KeyEvent) -> Self
fn from(key: KeyEvent) -> Self
Convert 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 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, termion::event::Key::Char('A') is converted to Input { key: Key::Char('A'), shift: false, .. }.
Source§impl From<MouseEvent> for Input
Available on crate features crossterm or tuirs-crossterm only.
impl From<MouseEvent> for Input
crossterm or tuirs-crossterm only.Source§fn from(mouse: MouseEvent) -> Self
fn from(mouse: MouseEvent) -> Self
Convert crossterm::event::MouseEvent into Input.
Source§impl From<MouseEvent> for Input
Available on crate features termion or tuirs-termion only.
impl From<MouseEvent> for Input
termion or tuirs-termion only.Source§fn from(mouse: MouseEvent) -> Self
fn from(mouse: MouseEvent) -> Self
Convert 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 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 termwiz::input::PixelMouseEvent into Input.
impl Eq for 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 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,
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