summaryrefslogtreecommitdiffstats
path: root/src/state.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-11-13 16:26:04 -0500
committerJesse Luehrs <doy@tozt.net>2021-11-13 16:26:04 -0500
commitb7a0201d42995e34df4f541b23826ff7ac42dd9f (patch)
treed1b3eb490889c71b0ce54f0123692007f72e7e11 /src/state.rs
parent57f3d0780492872490354d738ca4d8e3d5114ee6 (diff)
downloadnbsh-b7a0201d42995e34df4f541b23826ff7ac42dd9f.tar.gz
nbsh-b7a0201d42995e34df4f541b23826ff7ac42dd9f.zip
move escape character handling to the top level input handling
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs23
1 files changed, 23 insertions, 0 deletions
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<crate::action::Action>,
}
@@ -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,