pub enum Event {
FocusGained,
FocusLost,
Key(KeyEvent),
Mouse(MouseEvent),
Paste(String),
Resize(u16, u16),
}
Expand description
Represents an event.
Variants§
FocusGained
The terminal gained focus
FocusLost
The terminal lost focus
Key(KeyEvent)
A single key event with additional pressed modifiers.
Mouse(MouseEvent)
A single mouse event with additional pressed modifiers.
Paste(String)
A string that was pasted into the terminal. Only emitted if bracketed paste has been enabled.
Resize(u16, u16)
An resize event with new dimensions after resize (columns, rows). Note that resize events can occur in batches.
Implementations§
Source§impl Event
impl Event
Sourcepub const fn is_focus_gained(&self) -> bool
pub const fn is_focus_gained(&self) -> bool
Returns true
if this value is of type FocusGained
. Returns false
otherwise
Sourcepub const fn is_focus_lost(&self) -> bool
pub const fn is_focus_lost(&self) -> bool
Returns true
if this value is of type FocusLost
. Returns false
otherwise
Sourcepub const fn is_key(&self) -> bool
pub const fn is_key(&self) -> bool
Returns true
if this value is of type Key
. Returns false
otherwise
Sourcepub const fn is_mouse(&self) -> bool
pub const fn is_mouse(&self) -> bool
Returns true
if this value is of type Mouse
. Returns false
otherwise
Source§impl Event
impl Event
Sourcepub fn is_key_press(&self) -> bool
pub fn is_key_press(&self) -> bool
Returns true
if the event is a key press event.
This is useful for waiting for any key press event, regardless of the key that was pressed.
Returns false
for key release and repeat events (as well as for non-key events).
§Examples
The following code runs a loop that processes events until a key press event is encountered:
use crossterm::event;
while !event::read()?.is_key_press() {
// ...
}
Sourcepub fn is_key_release(&self) -> bool
pub fn is_key_release(&self) -> bool
Returns true
if the event is a key release event.
Sourcepub fn is_key_repeat(&self) -> bool
pub fn is_key_repeat(&self) -> bool
Returns true
if the event is a key repeat event.
Sourcepub fn as_key_event(&self) -> Option<KeyEvent>
pub fn as_key_event(&self) -> Option<KeyEvent>
Returns the key event if the event is a key event, otherwise None
.
This is a convenience method that makes apps that only care about key events easier to write.
§Examples
The following code runs a loop that only processes key events:
use crossterm::event;
while let Some(key_event) = event::read()?.as_key_event() {
// ...
}
Sourcepub fn as_key_press_event(&self) -> Option<KeyEvent>
pub fn as_key_press_event(&self) -> Option<KeyEvent>
Returns an Option containing the KeyEvent if the event is a key press event.
This is a convenience method that makes apps that only care about key press events, and not key release or repeat events (or non-key events), easier to write.
Returns None
for key release and repeat events (as well as for non-key events).
§Examples
The following code runs a loop that only processes key press events:
use crossterm::event;
while let Ok(event) = event::read() {
if let Some(key) = event.as_key_press_event() {
// ...
}
}
Sourcepub fn as_key_release_event(&self) -> Option<KeyEvent>
pub fn as_key_release_event(&self) -> Option<KeyEvent>
Returns an Option containing the KeyEvent
if the event is a key release event.
Sourcepub fn as_key_repeat_event(&self) -> Option<KeyEvent>
pub fn as_key_repeat_event(&self) -> Option<KeyEvent>
Returns an Option containing the KeyEvent
if the event is a key repeat event.
Sourcepub fn as_mouse_event(&self) -> Option<MouseEvent>
pub fn as_mouse_event(&self) -> Option<MouseEvent>
Returns the mouse event if the event is a mouse event, otherwise None
.
This is a convenience method that makes code which only cares about mouse events easier to write.
§Examples
use crossterm::event;
while let Some(mouse_event) = event::read()?.as_mouse_event() {
// ...
}
Sourcepub fn as_paste_event(&self) -> Option<&str>
pub fn as_paste_event(&self) -> Option<&str>
Returns the pasted string if the event is a paste event, otherwise None
.
This is a convenience method that makes code which only cares about paste events easier to write.
§Examples
use crossterm::event;
while let Some(paste) = event::read()?.as_paste_event() {
// ...
}
Sourcepub fn as_resize_event(&self) -> Option<(u16, u16)>
pub fn as_resize_event(&self) -> Option<(u16, u16)>
Returns the size as a tuple if the event is a resize event, otherwise None
.
This is a convenience method that makes code which only cares about resize events easier to write.
§Examples
use crossterm::event;
while let Some((columns, rows)) = event::read()?.as_resize_event() {
// ...
}