Skip to main content

Event

Enum Event 

Source
#[non_exhaustive]
pub enum Event { Key(KeyEvent), Mouse(MouseEvent), Resize(u32, u32), Paste(String), FocusGained, FocusLost, }
Expand description

A terminal input event.

Produced each frame by the run loop and passed to your UI closure via crate::Context. Use the helper methods on Context (e.g., key(), key_code()) rather than matching on this type directly.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Key(KeyEvent)

A keyboard event.

§

Mouse(MouseEvent)

A mouse event (requires mouse: true in crate::RunConfig).

§

Resize(u32, u32)

The terminal was resized to the given (columns, rows).

§

Paste(String)

Pasted text (bracketed paste). May contain newlines.

§

FocusGained

The terminal window gained focus.

§

FocusLost

The terminal window lost focus. Used to clear hover state.

Implementations§

Source§

impl Event

Source

pub fn key_char(c: char) -> Self

Create a key press event for a character.

Source

pub fn key(code: KeyCode) -> Self

Create a key press event for a special key.

Source

pub fn key_ctrl(c: char) -> Self

Create a key press event with Ctrl modifier.

Source

pub fn key_mod(code: KeyCode, modifiers: KeyModifiers) -> Self

Create a key press event with custom modifiers.

Source

pub fn resize(width: u32, height: u32) -> Self

Create a terminal resize event.

Source

pub fn mouse_click(x: u32, y: u32) -> Self

Create a left mouse click event at (x, y).

Source

pub fn mouse_move(x: u32, y: u32) -> Self

Create a mouse move event at the given position.

Source

pub fn scroll_up(x: u32, y: u32) -> Self

Create a scroll up event at the given position.

Source

pub fn scroll_down(x: u32, y: u32) -> Self

Create a scroll down event at the given position.

Source

pub fn key_release(c: char) -> Self

Create a key release event for a character.

Source

pub fn paste(text: impl Into<String>) -> Self

Create a paste event with the given text.

Source

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

Returns the key event data if this is a Key variant.

Source

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

Returns the mouse event data if this is a Mouse variant.

Source

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

Returns (columns, rows) if this is a Resize variant.

Source

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

Returns the pasted text if this is a Paste variant.

Source

pub fn is_key(&self) -> bool

Returns true if this is a Key event.

Source

pub fn is_mouse(&self) -> bool

Returns true if this is a Mouse event.

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

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 Debug for Event

Source§

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

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

impl PartialEq for Event

Source§

fn eq(&self, other: &Event) -> 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 Eq for Event

Source§

impl StructuralPartialEq for Event

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnsafeUnpin for Event

§

impl UnwindSafe for Event

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