From e7fa88dcd4b261af643a9aedfce0f0a1d9a97462 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 11 Nov 2021 15:19:31 -0500 Subject: handle dynamic terminal sizes --- src/action.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/action.rs') diff --git a/src/action.rs b/src/action.rs index 2cd54b7..81f83bb 100644 --- a/src/action.rs +++ b/src/action.rs @@ -3,6 +3,7 @@ pub enum Action { Render, Run(String), UpdateFocus(crate::state::Focus), + Resize((u16, u16)), } pub struct Debouncer { @@ -30,9 +31,10 @@ impl Debouncer { #[derive(Default)] struct Pending { - render: bool, + render: Option<()>, run: std::collections::VecDeque, focus: Option, + size: Option<(u16, u16)>, done: bool, } @@ -42,18 +44,24 @@ impl Pending { } fn has_event(&self) -> bool { - self.render || !self.run.is_empty() || self.focus.is_some() + self.render.is_some() + || !self.run.is_empty() + || self.focus.is_some() + || self.size.is_some() } fn get_event(&mut self) -> Option { + if self.size.is_some() { + return Some(Action::Resize(self.size.take().unwrap())); + } if !self.run.is_empty() { return Some(Action::Run(self.run.pop_front().unwrap())); } if self.focus.is_some() { return Some(Action::UpdateFocus(self.focus.take().unwrap())); } - if self.render { - self.render = false; + if self.render.is_some() { + self.render.take(); return Some(Action::Render); } if self.done { @@ -66,7 +74,8 @@ impl Pending { match action { Some(Action::Run(cmd)) => self.run.push_back(cmd.to_string()), Some(Action::UpdateFocus(focus)) => self.focus = Some(*focus), - Some(Action::Render) => self.render = true, + Some(Action::Render) => self.render = Some(()), + Some(Action::Resize(size)) => self.size = Some(*size), None => self.done = true, } } -- cgit v1.2.3-54-g00ecf