pub enum Event {
FocusGained,
FocusLost,
Key(KeyEvent),
Mouse(MouseEvent),
Paste(String),
Resize {
rows: u32,
cols: u32,
},
}
Expand description
An application event.
Variants§
FocusGained
The application gained focus.
FocusLost
The application lost focus.
Key(KeyEvent)
A keyboard input event.
Mouse(MouseEvent)
A mouse input event.
Paste(String)
A string that was pasted into the application.
Resize
An resize event with new dimensions after resize.
Implementations§
Source§impl Event
impl Event
Sourcepub fn encode(&self, buf: &mut [u8], encoding: Encoding) -> Result<usize>
pub fn encode(&self, buf: &mut [u8], encoding: Encoding) -> Result<usize>
Encode the event into the given buffer using the supplied Encoding
mode.
Returns the number of bytes written, following the semantics of std::io::Write::write
.
The supplied buffer needs enough space to hold the encoded sequence. If you’re unsure of how large the result will be, 16 bytes is more than sufficient.
§Example
use terminput::{Encoding, Event, KeyCode, KeyEvent};
let event = Event::Key(KeyEvent::new(KeyCode::Char('a')));
let mut buf = [0; 16];
let written = event.encode(&mut buf, Encoding::Xterm);
if let Ok(written) = written {
println!("Encoded: {:?}", &buf[..written]);
}
Source§impl Event
impl Event
Sourcepub fn as_key_press(&self, repeats: Repeats) -> Option<KeyEvent>
pub fn as_key_press(&self, repeats: Repeats) -> Option<KeyEvent>
Returns the contained event if it is a key press event.
If Repeats::Include
is passed, both KeyEventKind::Press
and KeyEventKind::Repeat
are considered press events.
If Repeats::Exclude
is passed, only KeyEventKind::Press
is considered.
Sourcepub fn is_key_press(&self, repeats: Repeats) -> bool
pub fn is_key_press(&self, repeats: Repeats) -> bool
Returns whether the contained event is a key press event.
If Repeats::Include
is passed, both KeyEventKind::Press
and KeyEventKind::Repeat
are considered press events.
If Repeats::Exclude
is passed, only KeyEventKind::Press
is considered.
Sourcepub fn as_key_repeat(&self) -> Option<KeyEvent>
pub fn as_key_repeat(&self) -> Option<KeyEvent>
Returns the contained event if it is a KeyEventKind::Repeat
key event.
Sourcepub fn is_key_repeat(&self) -> bool
pub fn is_key_repeat(&self) -> bool
Returns whether the contained event is a KeyEventKind::Repeat
key event.
Sourcepub fn as_key_release(&self) -> Option<KeyEvent>
pub fn as_key_release(&self) -> Option<KeyEvent>
Returns the contained event if it is a KeyEventKind::Release
key event.
Sourcepub fn is_key_release(&self) -> bool
pub fn is_key_release(&self) -> bool
Returns whether the contained event is a KeyEventKind::Release
key event.
Sourcepub fn as_mouse(&self) -> Option<MouseEvent>
pub fn as_mouse(&self) -> Option<MouseEvent>
Returns the contained event if it is a MouseEvent
.
Sourcepub fn is_mouse(&self) -> bool
pub fn is_mouse(&self) -> bool
Returns whether the contained event is a MouseEvent
.
Sourcepub fn as_mouse_down(&self) -> Option<(MouseEvent, MouseButton)>
pub fn as_mouse_down(&self) -> Option<(MouseEvent, MouseButton)>
Returns the contained event if it is a MouseEventKind::Down
mouse event.
Sourcepub fn is_mouse_down(&self) -> bool
pub fn is_mouse_down(&self) -> bool
Returns whether the event is a MouseEventKind::Down
mouse event.
Sourcepub fn as_mouse_up(&self) -> Option<(MouseEvent, MouseButton)>
pub fn as_mouse_up(&self) -> Option<(MouseEvent, MouseButton)>
Returns the contained event if it is a MouseEventKind::Up
mouse event.
Sourcepub fn is_mouse_up(&self) -> bool
pub fn is_mouse_up(&self) -> bool
Returns whether the event is a MouseEventKind::Up
mouse event.
Sourcepub fn as_mouse_drag(&self) -> Option<(MouseEvent, MouseButton)>
pub fn as_mouse_drag(&self) -> Option<(MouseEvent, MouseButton)>
Returns the contained event if it is a MouseEventKind::Drag
mouse event.
Sourcepub fn is_mouse_drag(&self) -> bool
pub fn is_mouse_drag(&self) -> bool
Returns whether the event is a MouseEventKind::Drag
mouse event.
Sourcepub fn as_mouse_move(&self) -> Option<MouseEvent>
pub fn as_mouse_move(&self) -> Option<MouseEvent>
Returns the contained event if it is a MouseEventKind::Moved
mouse event.
Sourcepub fn is_mouse_move(&self) -> bool
pub fn is_mouse_move(&self) -> bool
Returns whether the event is a MouseEventKind::Moved
mouse event.
Sourcepub fn as_mouse_scroll(&self) -> Option<(MouseEvent, ScrollDirection)>
pub fn as_mouse_scroll(&self) -> Option<(MouseEvent, ScrollDirection)>
Returns the contained event if it is a MouseEventKind::Scroll
mouse event.
Sourcepub fn is_mouse_scroll(&self) -> bool
pub fn is_mouse_scroll(&self) -> bool
Returns whether the event is a MouseEventKind::Scroll
mouse event.
Sourcepub fn is_focus_gained(&self) -> bool
pub fn is_focus_gained(&self) -> bool
Returns whether the event is Event::FocusGained
.
Sourcepub fn is_focus_lost(&self) -> bool
pub fn is_focus_lost(&self) -> bool
Returns whether the event is Event::FocusLost
.
Sourcepub fn as_paste(&self) -> Option<&str>
pub fn as_paste(&self) -> Option<&str>
Returns the pasted text if the event is Event::Paste
.
Sourcepub fn is_paste(&self) -> bool
pub fn is_paste(&self) -> bool
Returns whether the event is Event::Paste
.
Sourcepub fn as_resize(&self) -> Option<(u32, u32)>
pub fn as_resize(&self) -> Option<(u32, u32)>
Returns the (rows, cols)
from the contained event if it is a Event::Resize
event.
Sourcepub fn is_resize(&self) -> bool
pub fn is_resize(&self) -> bool
Returns whether the event is Event::Resize
.