From b7a0201d42995e34df4f541b23826ff7ac42dd9f Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 13 Nov 2021 16:26:04 -0500 Subject: move escape character handling to the top level input handling --- src/state.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/state.rs') diff --git a/src/state.rs b/src/state.rs index ff26a75..193d1af 100644 --- a/src/state.rs +++ b/src/state.rs @@ -5,6 +5,7 @@ pub struct State { history: crate::history::History, focus: Focus, output: textmode::Output, + escape: bool, action: async_std::channel::Sender, } @@ -21,6 +22,7 @@ impl State { history, focus, output, + escape: false, action, } } @@ -65,6 +67,27 @@ impl State { } pub async fn handle_input(&mut self, key: textmode::Key) -> bool { + if self.escape { + let mut ret = true; + match key { + textmode::Key::Ctrl(b'e') => { + ret = false; // fall through and handle normally + } + textmode::Key::Char('r') => { + self.focus = Focus::Readline; + self.render().await.unwrap(); + } + _ => {} + } + self.escape = false; + if ret { + return false; + } + } else if key == textmode::Key::Ctrl(b'e') { + self.escape = true; + return false; + } + match self.focus { Focus::Readline => self.readline.handle_key(key).await, Focus::History(idx) => self.history.handle_key(key, idx).await, -- cgit v1.2.3-54-g00ecf