pub struct Input {
    pub key: Key,
    pub ctrl: bool,
    pub alt: bool,
}
Expand description

Backend-agnostic key input type.

When crossterm and/or termion features are enabled, converting their 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);
// or `Into::into`
let input: Input = event.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,
});

Fields

key: Key

Typed key.

ctrl: bool

Ctrl modifier key. true means Ctrl key was pressed.

alt: bool

Alt modifier key. true means Alt key was pressed.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The default input is Key::Null without pressing any modifier keys, which means invalid input.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.