Event

Enum Event 

Source
pub enum Event<M> {
    Key(KeyEvent),
    Mouse(MouseEvent),
    Resize {
        width: u16,
        height: u16,
    },
    Tick,
    User(M),
    Quit,
    Focus,
    Blur,
    Suspend,
    Resume,
    Paste(String),
    // some variants omitted
}
Expand description

An event that can be received by the program

Variants§

§

Key(KeyEvent)

A keyboard event

§

Mouse(MouseEvent)

A mouse event

§

Resize

Terminal was resized

Fields

§width: u16

New terminal width in columns

§height: u16

New terminal height in rows

§

Tick

A tick event (for animations, etc.)

§

User(M)

User-defined message

§

Quit

Request to quit the program

§

Focus

Terminal gained focus

§

Blur

Terminal lost focus

§

Suspend

Program suspend request (Ctrl+Z)

§

Resume

Program resumed from suspend

§

Paste(String)

Bracketed paste event

Implementations§

Source§

impl<M> Event<M>

Source

pub const fn is_key(&self) -> bool

Check if this is a key event

Source

pub fn is_key_press(&self, key: Key) -> bool

Check if this is a specific key press

§Example
if event.is_key_press(Key::Enter) {
    // Handle enter key
}
Source

pub fn is_key_with_modifiers(&self, key: Key, modifiers: KeyModifiers) -> bool

Check if this is a specific key with modifiers

§Example
if event.is_key_with_modifiers(Key::Char('c'), KeyModifiers::CONTROL) {
    // Handle Ctrl+C
}
Source

pub const fn as_key(&self) -> Option<&KeyEvent>

Get the key event if this is a key event

Source

pub const fn is_mouse(&self) -> bool

Check if this is a mouse event

Source

pub const fn as_mouse(&self) -> Option<&MouseEvent>

Get the mouse event if this is a mouse event

Source

pub fn is_click(&self) -> bool

Check if this is a mouse click at any position

Source

pub fn as_click(&self) -> Option<(u16, u16)>

Get click position if this is a click event

§Example
if let Some((x, y)) = event.as_click() {
    // Handle click at position (x, y)
}
Source

pub fn is_resize(&self) -> bool

Check if this is a resize event

Source

pub fn as_resize(&self) -> Option<(u16, u16)>

Get resize dimensions if this is a resize event

§Example
if let Some((width, height)) = event.as_resize() {
    // Handle resize to width x height
}
Source

pub const fn is_user(&self) -> bool

Check if this is a user message

Source

pub const fn as_user(&self) -> Option<&M>

Get the user message if this is a user event

Source

pub fn into_user(self) -> Option<M>

Take the user message if this is a user event

Source

pub const fn is_quit(&self) -> bool

Check if this is a quit event

Source

pub const fn is_tick(&self) -> bool

Check if this is a tick event

Source

pub fn is_paste(&self) -> bool

Check if this is a paste event

Source

pub fn as_paste(&self) -> Option<&str>

Get pasted text if this is a paste event

Source

pub fn is_focus(&self) -> bool

Check if this is a focus event

Source

pub fn is_blur(&self) -> bool

Check if this is a blur event

Source

pub fn is_suspend(&self) -> bool

Check if this is a suspend event

Source

pub fn is_resume(&self) -> bool

Check if this is a resume event

Trait Implementations§

Source§

impl<M> Clone for Event<M>
where M: Clone,

Source§

fn clone(&self) -> Event<M>

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

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

Performs copy-assignment from source. Read more
Source§

impl<M> Debug for Event<M>
where M: Debug,

Source§

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

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

impl<M> From<OptimizedEvent<M>> for Event<M>

Convert from OptimizedEvent back to standard Event

Source§

fn from(event: OptimizedEvent<M>) -> Event<M>

Converts to this type from the input type.
Source§

impl<M> PartialEq for Event<M>
where M: PartialEq,

Source§

fn eq(&self, other: &Event<M>) -> bool

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

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<M> StructuralPartialEq for Event<M>

Auto Trait Implementations§

§

impl<M> Freeze for Event<M>
where M: Freeze,

§

impl<M> RefUnwindSafe for Event<M>
where M: RefUnwindSafe,

§

impl<M> Send for Event<M>
where M: Send,

§

impl<M> Sync for Event<M>
where M: Sync,

§

impl<M> Unpin for Event<M>
where M: Unpin,

§

impl<M> UnwindSafe for Event<M>
where M: UnwindSafe,

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> Inspectable for T

Source§

fn inspect(self, label: &str) -> Self
where Self: Debug,

Inspect this value with a label
Source§

fn inspect_if(self, condition: bool, label: &str) -> Self
where Self: Debug,

Conditionally inspect this value
Source§

fn inspect_with<F>(self, label: &str, f: F) -> Self
where F: FnOnce(&Self) -> String,

Inspect with a custom formatter
Source§

fn tap<F>(self, f: F) -> Self
where F: FnOnce(&Self),

Tap into the value for side effects
Source§

fn tap_if<F>(self, condition: bool, f: F) -> Self
where F: FnOnce(&Self),

Conditionally tap into the value
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, 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> Message for T
where T: Send + 'static,