Events

Struct Events 

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

Helper struct to read from crossterm’s input events

Implementations§

Source§

impl Events

Source

pub fn from_config(config: Config) -> Events

Creates an Events instance from Config and starts a thread to listen on crossterm input events

Source

pub fn next(&self) -> Result<Option<Event>, RecvError>

Checks if there was a new event to read from. Returns Some(Event) if there was some, None if not and Result::Err if the connection was disconnected.

Examples found in repository?
examples/command/main.rs (line 32)
31fn handle_input(tui: &mut TuiClap, events: &Events) {
32    if let Ok(Some(Event::Key(key_event))) = events.next() {
33        match key_event.code {
34            KeyCode::Backspace => {
35                tui.state().del_char()
36            }
37            KeyCode::Enter => {
38                if let Ok(matches) = tui.parse() {
39                    match handle_matches(matches) {
40                        Ok(output) => {
41                            for message in output {
42                                tui.write_to_output(message)
43                            }
44                        }
45                        Err(err) => tui.write_to_output(err)
46                    }
47                }
48            }
49            KeyCode::Char(char) => {
50                tui.state().add_char(char)
51            },
52            _ => {}
53        }
54    }
55}
Source

pub fn disable_exit_key(&mut self)

Source

pub fn enable_exit_key(&mut self)

Trait Implementations§

Source§

impl Default for Events

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Events

§

impl RefUnwindSafe for Events

§

impl Send for Events

§

impl !Sync for Events

§

impl Unpin for Events

§

impl UnwindSafe for Events

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