pub enum CrosstermEvent {
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() {
// ...
}Trait Implementations§
Source§impl PartialOrd for Event
impl PartialOrd for Event
impl Eq for Event
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more