pub enum Event {
FocusGained,
FocusLost,
Key(KeyEvent),
Mouse(MouseEvent),
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.
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 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_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() {
// ...
}