diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-11 01:39:30 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-11 01:39:30 -0500 |
commit | fba274231f42e868b34284112ecae18bb46bf029 (patch) | |
tree | 91c0bb2efa41dfe465fb9a2c006baa21adc2ecaa | |
parent | a87e03fa707cfdd9779334d4bf177188bb54db5b (diff) | |
download | nbsh-fba274231f42e868b34284112ecae18bb46bf029.tar.gz nbsh-fba274231f42e868b34284112ecae18bb46bf029.zip |
redo a bunch of keybindings, fix fullscreen behavior a bit
-rw-r--r-- | src/history.rs | 11 | ||||
-rw-r--r-- | src/state.rs | 105 |
2 files changed, 63 insertions, 53 deletions
diff --git a/src/history.rs b/src/history.rs index 2753470..fbcd2d8 100644 --- a/src/history.rs +++ b/src/history.rs @@ -130,6 +130,13 @@ impl History { self.entries[idx].lock_arc().await.toggle_fullscreen(); } + pub async fn set_fullscreen(&mut self, idx: usize, fullscreen: bool) { + self.entries[idx] + .lock_arc() + .await + .set_fullscreen(fullscreen); + } + pub async fn should_fullscreen(&self, idx: usize) -> bool { self.entries[idx].lock_arc().await.should_fullscreen() } @@ -321,6 +328,10 @@ impl HistoryEntry { } } + fn set_fullscreen(&mut self, fullscreen: bool) { + self.fullscreen = Some(fullscreen); + } + fn running(&self) -> bool { self.exit_info.is_none() } diff --git a/src/state.rs b/src/state.rs index 9ab76ce..f23c0d2 100644 --- a/src/state.rs +++ b/src/state.rs @@ -56,51 +56,39 @@ 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; } - None - } - textmode::Key::Ctrl(b'l') => { - Some(crate::action::Action::ForceRedraw) - } - textmode::Key::Char('f') => { - if let crate::action::Focus::History(idx) = self.focus { - self.history.toggle_fullscreen(idx).await; - Some(crate::action::Action::CheckUpdateScene) - } else { - None - } } textmode::Key::Ctrl(b'e') => { - Some(crate::action::Action::UpdateFocus( - crate::action::Focus::Scrolling(self.focus_idx()), - )) - } - textmode::Key::Char('j') | textmode::Key::Down => { - Some(crate::action::Action::UpdateFocus( - crate::action::Focus::Scrolling( - self.scroll_down(self.focus_idx()), - ), - )) - } - textmode::Key::Char('k') | textmode::Key::Up => { - Some(crate::action::Action::UpdateFocus( - crate::action::Focus::Scrolling( - self.scroll_up(self.focus_idx()), - ), + self.set_focus(crate::action::Focus::Scrolling( + self.focus_idx(), )) + .await; } textmode::Key::Char('r') => { - Some(crate::action::Action::UpdateFocus( - crate::action::Focus::Readline, - )) + self.set_focus(crate::action::Focus::Readline).await; } - _ => None, + 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( @@ -109,6 +97,12 @@ impl State { 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 focus = if let Some(idx) = idx { self.history.running(idx).await @@ -116,42 +110,43 @@ impl State { true }; if focus { - Some(crate::action::Action::UpdateFocus( + self.set_focus( idx.map_or(crate::action::Focus::Readline, |idx| { crate::action::Focus::History(idx) }), - )) - } else { - None + ) + .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; + self.scene = self.default_scene(self.focus).await; } } textmode::Key::Char('j') | textmode::Key::Down => { - Some(crate::action::Action::UpdateFocus( - crate::action::Focus::Scrolling( - self.scroll_down(self.focus_idx()), - ), + self.set_focus(crate::action::Focus::Scrolling( + self.scroll_down(self.focus_idx()), )) + .await; } textmode::Key::Char('k') | textmode::Key::Up => { - Some(crate::action::Action::UpdateFocus( - crate::action::Focus::Scrolling( - self.scroll_up(self.focus_idx()), - ), + self.set_focus(crate::action::Focus::Scrolling( + self.scroll_up(self.focus_idx()), )) + .await; } textmode::Key::Char(' ') => { if let Some(idx) = self.focus_idx() { self.readline .set_input(&self.history.history_cmd(idx).await); - Some(crate::action::Action::UpdateFocus( - crate::action::Focus::Readline, - )) - } else { - None + self.set_focus(crate::action::Focus::Readline).await; } } - _ => None, + _ => {} } + Some(crate::action::Action::Render) } pub async fn render( @@ -245,9 +240,7 @@ impl State { self.hide_readline = true; } crate::action::Action::UpdateFocus(new_focus) => { - self.focus = new_focus; - self.hide_readline = false; - self.scene = self.default_scene(new_focus).await; + self.set_focus(new_focus).await; } crate::action::Action::UpdateScene(new_scene) => { self.scene = new_scene; @@ -288,6 +281,12 @@ impl State { } } + async fn set_focus(&mut self, new_focus: crate::action::Focus) { + self.focus = new_focus; + self.hide_readline = false; + self.scene = self.default_scene(new_focus).await; + } + fn focus_idx(&self) -> Option<usize> { match self.focus { crate::action::Focus::History(idx) => Some(idx), |