summaryrefslogtreecommitdiffstats
path: root/src
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
parent57f3d0780492872490354d738ca4d8e3d5114ee6 (diff)
downloadnbsh-b7a0201d42995e34df4f541b23826ff7ac42dd9f.tar.gz
nbsh-b7a0201d42995e34df4f541b23826ff7ac42dd9f.zip
move escape character handling to the top level input handling
Diffstat (limited to 'src')
-rw-r--r--src/history.rs54
-rw-r--r--src/state.rs23
2 files changed, 30 insertions, 47 deletions
diff --git a/src/history.rs b/src/history.rs
index 86fed66..5397c68 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -6,7 +6,6 @@ use textmode::Textmode as _;
pub struct History {
size: (u16, u16),
entries: Vec<crate::util::Mutex<HistoryEntry>>,
- escape: bool,
action: async_std::channel::Sender<crate::action::Action>,
}
@@ -17,7 +16,6 @@ impl History {
Self {
size: (24, 80),
entries: vec![],
- escape: false,
action,
}
}
@@ -134,36 +132,13 @@ impl History {
key: textmode::Key,
idx: usize,
) -> bool {
- if self.escape {
- match key {
- textmode::Key::Ctrl(b'e') => {
- self.send_process_input(idx, &key.into_bytes())
- .await
- .unwrap();
- }
- textmode::Key::Char('r') => {
- self.action
- .send(crate::action::Action::UpdateFocus(
- crate::state::Focus::Readline,
- ))
- .await
- .unwrap();
- }
- _ => {}
- }
- self.escape = false;
- } else {
- match key {
- textmode::Key::Ctrl(b'e') => {
- self.escape = true;
- }
- key => {
- self.send_process_input(idx, &key.into_bytes())
- .await
- .unwrap();
- }
- }
- }
+ self.entries[idx]
+ .lock_arc()
+ .await
+ .input
+ .send(key.into_bytes())
+ .await
+ .unwrap();
false
}
@@ -219,21 +194,6 @@ impl History {
}
}
}
-
- async fn send_process_input(
- &self,
- idx: usize,
- input: &[u8],
- ) -> anyhow::Result<()> {
- self.entries[idx]
- .lock_arc()
- .await
- .input
- .send(input.to_vec())
- .await
- .unwrap();
- Ok(())
- }
}
struct HistoryEntry {
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,