summaryrefslogtreecommitdiffstats
path: root/src/state.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-11-11 15:19:31 -0500
committerJesse Luehrs <doy@tozt.net>2021-11-11 15:19:31 -0500
commite7fa88dcd4b261af643a9aedfce0f0a1d9a97462 (patch)
tree60cc330de5c038c4f1534b142c600a6e0a87f624 /src/state.rs
parent7a411e269b59cb7754eadacaf29a18e02845040b (diff)
downloadnbsh-e7fa88dcd4b261af643a9aedfce0f0a1d9a97462.tar.gz
nbsh-e7fa88dcd4b261af643a9aedfce0f0a1d9a97462.zip
handle dynamic terminal sizes
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/state.rs b/src/state.rs
index 854c306..2d5154a 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -5,21 +5,23 @@ pub struct State {
history: crate::history::History,
focus: Focus,
output: textmode::Output,
+ action: async_std::channel::Sender<crate::action::Action>,
}
impl State {
pub fn new(
- actions: async_std::channel::Sender<crate::action::Action>,
+ action: async_std::channel::Sender<crate::action::Action>,
output: textmode::Output,
) -> Self {
- let readline = crate::readline::Readline::new(actions.clone());
- let history = crate::history::History::new(actions);
+ let readline = crate::readline::Readline::new(action.clone());
+ let history = crate::history::History::new(action.clone());
let focus = Focus::Readline;
Self {
readline,
history,
focus,
output,
+ action,
}
}
@@ -52,6 +54,13 @@ impl State {
self.focus = new_focus;
self.render().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.clear();
+ self.render().await.unwrap();
+ }
}
}
@@ -61,6 +70,17 @@ impl State {
Focus::History(idx) => self.history.handle_key(key, idx).await,
}
}
+
+ pub async fn resize(&mut self) {
+ let size = terminal_size::terminal_size().map_or(
+ (24, 80),
+ |(terminal_size::Width(w), terminal_size::Height(h))| (h, w),
+ );
+ self.action
+ .send(crate::action::Action::Resize(size))
+ .await
+ .unwrap();
+ }
}
#[derive(Copy, Clone, Debug)]