diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-11 02:08:27 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-11 02:08:27 -0500 |
commit | 86bedf54342eda4e3f10dc34523612209a9f2685 (patch) | |
tree | 236ff0c38fa1d37cc4282a7968fd358218e5bf6c /src/state.rs | |
parent | fba274231f42e868b34284112ecae18bb46bf029 (diff) | |
download | nbsh-86bedf54342eda4e3f10dc34523612209a9f2685.tar.gz nbsh-86bedf54342eda4e3f10dc34523612209a9f2685.zip |
simplify
Diffstat (limited to 'src/state.rs')
-rw-r--r-- | src/state.rs | 83 |
1 files changed, 35 insertions, 48 deletions
diff --git a/src/state.rs b/src/state.rs index f23c0d2..c030e2a 100644 --- a/src/state.rs +++ b/src/state.rs @@ -44,8 +44,8 @@ impl State { self.history.handle_key(key, idx).await; None } - crate::action::Focus::Scrolling(idx) => { - self.handle_key_scrolling(key, idx).await + crate::action::Focus::Scrolling(_) => { + self.handle_key_escape(key).await } } } @@ -56,15 +56,8 @@ impl State { key: textmode::Key, ) -> Option<crate::action::Action> { match key { - textmode::Key::Ctrl(b'l') => { - return Some(crate::action::Action::ForceRedraw); - } - textmode::Key::Char('e') => { - if let crate::action::Focus::History(idx) = self.focus { - self.history - .handle_key(textmode::Key::Ctrl(b'e'), idx) - .await; - } + textmode::Key::Ctrl(b'd') => { + return Some(crate::action::Action::Quit); } textmode::Key::Ctrl(b'e') => { self.set_focus(crate::action::Focus::Scrolling( @@ -72,38 +65,11 @@ impl State { )) .await; } - textmode::Key::Char('r') => { - self.set_focus(crate::action::Focus::Readline).await; - } - textmode::Key::Char('f') => { - if let Some(idx) = self.focus_idx() { - if let crate::action::Focus::Scrolling(_) = self.focus { - self.history.set_fullscreen(idx, true).await; - } else { - self.history.toggle_fullscreen(idx).await; - } - self.set_focus(crate::action::Focus::History(idx)).await; - self.scene = self.default_scene(self.focus).await; - } - } - _ => {} - } - Some(crate::action::Action::Render) - } - - async fn handle_key_scrolling( - &mut self, - key: textmode::Key, - idx: Option<usize>, - ) -> Option<crate::action::Action> { - match key { - textmode::Key::Ctrl(b'd') => { - return Some(crate::action::Action::Quit); - } textmode::Key::Ctrl(b'l') => { return Some(crate::action::Action::ForceRedraw); } textmode::Key::Ctrl(b'm') => { + let idx = self.focus_idx(); let focus = if let Some(idx) = idx { self.history.running(idx).await } else { @@ -118,10 +84,35 @@ impl State { .await; } } + textmode::Key::Char(' ') => { + if let Some(idx) = self.focus_idx() { + self.readline + .set_input(&self.history.history_cmd(idx).await); + self.set_focus(crate::action::Focus::Readline).await; + } + } + textmode::Key::Char('e') => { + if let crate::action::Focus::History(idx) = self.focus { + self.history + .handle_key(textmode::Key::Ctrl(b'e'), idx) + .await; + } + } textmode::Key::Char('f') => { - if let Some(idx) = idx { - self.set_focus(crate::action::Focus::History(idx)).await; - self.history.set_fullscreen(idx, true).await; + if let Some(idx) = self.focus_idx() { + let mut focus = crate::action::Focus::History(idx); + if let crate::action::Focus::Scrolling(_) = self.focus { + self.history.set_fullscreen(idx, true).await; + } else { + self.history.toggle_fullscreen(idx).await; + if !self.history.should_fullscreen(idx).await + && !self.history.running(idx).await + { + focus = + crate::action::Focus::Scrolling(Some(idx)); + } + } + self.set_focus(focus).await; self.scene = self.default_scene(self.focus).await; } } @@ -137,12 +128,8 @@ impl State { )) .await; } - textmode::Key::Char(' ') => { - if let Some(idx) = self.focus_idx() { - self.readline - .set_input(&self.history.history_cmd(idx).await); - self.set_focus(crate::action::Focus::Readline).await; - } + textmode::Key::Char('r') => { + self.set_focus(crate::action::Focus::Readline).await; } _ => {} } |