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
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>
impl<M> Event<M>
Sourcepub fn is_key_press(&self, key: Key) -> bool
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
}Sourcepub fn is_key_with_modifiers(&self, key: Key, modifiers: KeyModifiers) -> bool
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
}Sourcepub const fn as_mouse(&self) -> Option<&MouseEvent>
pub const fn as_mouse(&self) -> Option<&MouseEvent>
Get the mouse event if this is a mouse event
Sourcepub fn as_click(&self) -> Option<(u16, u16)>
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)
}Sourcepub fn as_resize(&self) -> Option<(u16, u16)>
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
}Sourcepub fn is_suspend(&self) -> bool
pub fn is_suspend(&self) -> bool
Check if this is a suspend event
Trait Implementations§
Source§impl<M> From<OptimizedEvent<M>> for Event<M>
Convert from OptimizedEvent back to standard Event
impl<M> From<OptimizedEvent<M>> for Event<M>
Convert from OptimizedEvent back to standard Event
Source§fn from(event: OptimizedEvent<M>) -> Event<M>
fn from(event: OptimizedEvent<M>) -> Event<M>
Converts to this type from the input type.
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> 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Inspectable for T
impl<T> Inspectable for T
Source§fn inspect_if(self, condition: bool, label: &str) -> Selfwhere
Self: Debug,
fn inspect_if(self, condition: bool, label: &str) -> Selfwhere
Self: Debug,
Conditionally inspect this value
Source§fn inspect_with<F>(self, label: &str, f: F) -> Self
fn inspect_with<F>(self, label: &str, f: F) -> Self
Inspect with a custom formatter