summaryrefslogtreecommitdiffstats
path: root/src/action.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-11 17:54:10 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-11 17:55:19 -0500
commit62fe2477fb8bbbfbca34779b992979f9c1a8ba53 (patch)
treea4c12df90fefa5b1f2b81905ed3f6ca2d1dcd079 /src/action.rs
parent6ca82f5be15f1c6c936c82266d1f6dc13185346c (diff)
downloadnbsh-62fe2477fb8bbbfbca34779b992979f9c1a8ba53.tar.gz
nbsh-62fe2477fb8bbbfbca34779b992979f9c1a8ba53.zip
move key handling into the main event loop
Diffstat (limited to 'src/action.rs')
-rw-r--r--src/action.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/action.rs b/src/action.rs
index 2cb28c1..ff0402b 100644
--- a/src/action.rs
+++ b/src/action.rs
@@ -1,5 +1,6 @@
#[derive(Debug)]
pub enum Action {
+ Key(textmode::Key),
Render,
ForceRedraw,
Run(String),
@@ -67,6 +68,7 @@ impl Reader {
#[derive(Default)]
struct Pending {
+ key: std::collections::VecDeque<textmode::Key>,
render: Option<()>,
force_redraw: Option<()>,
run: std::collections::VecDeque<String>,
@@ -84,6 +86,7 @@ impl Pending {
fn has_action(&self) -> bool {
self.done
+ || !self.key.is_empty()
|| self.render.is_some()
|| self.force_redraw.is_some()
|| !self.run.is_empty()
@@ -97,6 +100,9 @@ impl Pending {
if self.done {
return None;
}
+ if !self.key.is_empty() {
+ return Some(Action::Key(self.key.pop_front().unwrap()));
+ }
if self.size.is_some() {
return Some(Action::Resize(self.size.take().unwrap()));
}
@@ -124,6 +130,7 @@ impl Pending {
fn new_action(&mut self, action: &Option<Action>) {
match action {
+ Some(Action::Key(key)) => self.key.push_back(key.clone()),
Some(Action::Render) => self.render = Some(()),
Some(Action::ForceRedraw) => self.force_redraw = Some(()),
Some(Action::Run(cmd)) => self.run.push_back(cmd.to_string()),