diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-11-16 14:10:24 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-11-16 14:10:24 -0500 |
commit | 9edb92d2715a7d0bd67a977454f1c648367dad40 (patch) | |
tree | a70d8851de516e81da696991a865e4de2f72d7b7 /src | |
parent | 0e102f53da61de230de8b4c4879c046b8c6baf4d (diff) | |
download | nbsh-9edb92d2715a7d0bd67a977454f1c648367dad40.tar.gz nbsh-9edb92d2715a7d0bd67a977454f1c648367dad40.zip |
add ^L (or ^E^L) to force-redraw the screen
Diffstat (limited to 'src')
-rw-r--r-- | src/action.rs | 11 | ||||
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | src/readline.rs | 6 | ||||
-rw-r--r-- | src/state.rs | 28 |
4 files changed, 36 insertions, 11 deletions
diff --git a/src/action.rs b/src/action.rs index 81f83bb..2e27393 100644 --- a/src/action.rs +++ b/src/action.rs @@ -1,6 +1,7 @@ #[derive(Debug)] pub enum Action { Render, + ForceRedraw, Run(String), UpdateFocus(crate::state::Focus), Resize((u16, u16)), @@ -32,6 +33,7 @@ impl Debouncer { #[derive(Default)] struct Pending { render: Option<()>, + force_redraw: Option<()>, run: std::collections::VecDeque<String>, focus: Option<crate::state::Focus>, size: Option<(u16, u16)>, @@ -45,6 +47,7 @@ impl Pending { fn has_event(&self) -> bool { self.render.is_some() + || self.force_redraw.is_some() || !self.run.is_empty() || self.focus.is_some() || self.size.is_some() @@ -60,6 +63,11 @@ impl Pending { if self.focus.is_some() { return Some(Action::UpdateFocus(self.focus.take().unwrap())); } + if self.force_redraw.is_some() { + self.force_redraw.take(); + self.render.take(); + return Some(Action::ForceRedraw); + } if self.render.is_some() { self.render.take(); return Some(Action::Render); @@ -72,9 +80,10 @@ impl Pending { fn new_event(&mut self, action: &Option<Action>) { match action { + Some(Action::Render) => self.render = Some(()), + Some(Action::ForceRedraw) => self.force_redraw = Some(()), Some(Action::Run(cmd)) => self.run.push_back(cmd.to_string()), Some(Action::UpdateFocus(focus)) => self.focus = Some(*focus), - Some(Action::Render) => self.render = Some(()), Some(Action::Resize(size)) => self.size = Some(*size), None => self.done = true, } diff --git a/src/main.rs b/src/main.rs index 5c59f08..6247d9f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ async fn async_main() -> anyhow::Result<()> { let (action_w, action_r) = async_std::channel::unbounded(); let mut state = state::State::new(action_w, output); - state.render().await.unwrap(); + state.render(true).await.unwrap(); let state = util::mutex(state); diff --git a/src/readline.rs b/src/readline.rs index ceaff0e..2040c10 100644 --- a/src/readline.rs +++ b/src/readline.rs @@ -32,6 +32,12 @@ impl Readline { textmode::Key::Ctrl(b'd') => { return true; } + textmode::Key::Ctrl(b'l') => { + self.action + .send(crate::action::Action::ForceRedraw) + .await + .unwrap(); + } textmode::Key::Ctrl(b'm') => { self.action .send(crate::action::Action::Run(self.input())) diff --git a/src/state.rs b/src/state.rs index 67a29e8..82f8735 100644 --- a/src/state.rs +++ b/src/state.rs @@ -27,7 +27,7 @@ impl State { } } - pub async fn render(&mut self) -> anyhow::Result<()> { + pub async fn render(&mut self, hard: bool) -> anyhow::Result<()> { self.output.clear(); match self.focus { Focus::Readline => { @@ -40,28 +40,35 @@ impl State { self.history.render(&mut self.output, 0, Some(idx)).await?; } } - self.output.refresh().await?; + if hard { + self.output.hard_refresh().await?; + } else { + self.output.refresh().await?; + } Ok(()) } pub async fn handle_action(&mut self, action: crate::action::Action) { match action { crate::action::Action::Render => { - self.render().await.unwrap(); + self.render(false).await.unwrap(); + } + crate::action::Action::ForceRedraw => { + self.render(true).await.unwrap(); } crate::action::Action::Run(ref cmd) => { self.history.run(cmd).await.unwrap(); } crate::action::Action::UpdateFocus(new_focus) => { self.focus = new_focus; - self.render().await.unwrap(); + self.render(false).await.unwrap(); } crate::action::Action::Resize(new_size) => { self.readline.resize(new_size).await; self.history.resize(new_size).await; self.output.set_size(new_size.0, new_size.1); self.output.hard_refresh().await.unwrap(); - self.render().await.unwrap(); + self.render(false).await.unwrap(); } } } @@ -73,10 +80,13 @@ impl State { textmode::Key::Ctrl(b'e') => { ret = false; // fall through and handle normally } + textmode::Key::Ctrl(b'l') => { + self.render(true).await.unwrap(); + } textmode::Key::Char('f') => { if let Focus::History(idx) = self.focus { self.history.toggle_fullscreen(idx).await; - self.render().await.unwrap(); + self.render(false).await.unwrap(); } } textmode::Key::Char('j') => { @@ -91,7 +101,7 @@ impl State { Focus::Readline => Focus::Readline, }; self.focus = new_focus; - self.render().await.unwrap(); + self.render(false).await.unwrap(); } textmode::Key::Char('k') => { let new_focus = match self.focus { @@ -107,11 +117,11 @@ impl State { } }; self.focus = new_focus; - self.render().await.unwrap(); + self.render(false).await.unwrap(); } textmode::Key::Char('r') => { self.focus = Focus::Readline; - self.render().await.unwrap(); + self.render(false).await.unwrap(); } _ => {} } |