From ac4ed1c0ccaa70c5ed41d65eee0844c3024da9b6 Mon Sep 17 00:00:00 2001 From: Tim Dubbins <57918941+timdubbins@users.noreply.github.com> Date: Sun, 10 Sep 2023 18:43:48 +0100 Subject: [PATCH] Add method to return character from char event. (#744) * Add method to return character from char event. * return the char for AltChar and CtrlChar events also --------- Co-authored-by: tidub <57918941+tidub@users.noreply.github.com> --- cursive-core/src/event.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cursive-core/src/event.rs b/cursive-core/src/event.rs index a9c0ca52..63de73cb 100644 --- a/cursive-core/src/event.rs +++ b/cursive-core/src/event.rs @@ -533,6 +533,16 @@ pub enum Event { } impl Event { + /// Returns the character, if `self` is a char event. + pub fn char(&self) -> Option { + match *self { + Event::Char(c) => Some(c), + Event::AltChar(c) => Some(c), + Event::CtrlChar(c) => Some(c), + _ => None, + } + } + /// Returns the position of the mouse, if `self` is a mouse event. pub fn mouse_position(&self) -> Option { if let Event::Mouse { position, .. } = *self { @@ -542,7 +552,7 @@ impl Event { } } - /// Returns a mutable reference to the position of the mouse/ + /// Returns a mutable reference to the position of the mouse. /// /// Returns `None` if `self` is not a mouse event. pub fn mouse_position_mut(&mut self) -> Option<&mut Vec2> {