summaryrefslogtreecommitdiffstats
path: root/src/state.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-11-18 02:09:43 -0500
committerJesse Luehrs <doy@tozt.net>2021-11-18 02:09:43 -0500
commit172115528605bacc5af3995a74ea60168f2b0d90 (patch)
tree40abd948830ca188d4e5b190ea3e2e44141e0fe3 /src/state.rs
parent04068bf2ad233748af1ac98edb12a27bf8ffca75 (diff)
downloadnbsh-172115528605bacc5af3995a74ea60168f2b0d90.tar.gz
nbsh-172115528605bacc5af3995a74ea60168f2b0d90.zip
refactor to potentially allow for displaying other things
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs75
1 files changed, 54 insertions, 21 deletions
diff --git a/src/state.rs b/src/state.rs
index c348d7f..155034e 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -4,6 +4,7 @@ pub struct State {
readline: crate::readline::Readline,
history: crate::history::History,
focus: Focus,
+ scene: Scene,
escape: bool,
hide_readline: bool,
}
@@ -13,10 +14,12 @@ impl State {
let readline = crate::readline::Readline::new();
let history = crate::history::History::new();
let focus = Focus::Readline;
+ let scene = Scene::Readline;
Self {
readline,
history,
focus,
+ scene,
escape: false,
hide_readline: false,
}
@@ -38,9 +41,8 @@ impl State {
}
textmode::Key::Char('f') => {
if let Focus::History(idx) = self.focus {
- return Some(
- crate::action::Action::ToggleFullscreen(idx),
- );
+ self.history.toggle_fullscreen(idx).await;
+ return Some(crate::action::Action::CheckUpdateScene);
}
}
textmode::Key::Char('j') => {
@@ -105,24 +107,32 @@ impl State {
hard: bool,
) -> anyhow::Result<()> {
out.clear();
- match self.focus {
- Focus::Readline => {
- self.history
- .render(out, self.readline.lines(), None)
- .await?;
- self.readline.render(out, true).await?;
- }
- Focus::History(idx) => {
- if self.hide_readline || self.history.is_fullscreen(idx).await
- {
- self.history.render(out, 0, Some(idx)).await?;
- } else {
+ match self.scene {
+ Scene::Readline => match self.focus {
+ Focus::Readline => {
self.history
- .render(out, self.readline.lines(), Some(idx))
+ .render(out, self.readline.lines(), None)
.await?;
- let pos = out.screen().cursor_position();
- self.readline.render(out, false).await?;
- out.move_to(pos.0, pos.1);
+ self.readline.render(out, true).await?;
+ }
+ Focus::History(idx) => {
+ if self.hide_readline {
+ self.history.render(out, 0, Some(idx)).await?;
+ } else {
+ self.history
+ .render(out, self.readline.lines(), Some(idx))
+ .await?;
+ let pos = out.screen().cursor_position();
+ self.readline.render(out, false).await?;
+ out.move_to(pos.0, pos.1);
+ }
+ }
+ },
+ Scene::Fullscreen => {
+ if let Focus::History(idx) = self.focus {
+ self.history.render_fullscreen(out, idx).await;
+ } else {
+ unreachable!();
}
}
}
@@ -155,9 +165,13 @@ impl State {
crate::action::Action::UpdateFocus(new_focus) => {
self.focus = new_focus;
self.hide_readline = false;
+ self.scene = self.default_scene(new_focus).await;
}
- crate::action::Action::ToggleFullscreen(idx) => {
- self.history.toggle_fullscreen(idx).await;
+ crate::action::Action::UpdateScene(new_scene) => {
+ self.scene = new_scene;
+ }
+ crate::action::Action::CheckUpdateScene => {
+ self.scene = self.default_scene(self.focus).await;
}
crate::action::Action::Resize(new_size) => {
self.readline.resize(new_size).await;
@@ -172,6 +186,19 @@ impl State {
}
self.render(out, hard_refresh).await.unwrap();
}
+
+ async fn default_scene(&self, focus: Focus) -> Scene {
+ match focus {
+ Focus::Readline => Scene::Readline,
+ Focus::History(idx) => {
+ if self.history.should_fullscreen(idx).await {
+ Scene::Fullscreen
+ } else {
+ Scene::Readline
+ }
+ }
+ }
+ }
}
#[derive(Copy, Clone, Debug)]
@@ -179,3 +206,9 @@ pub enum Focus {
Readline,
History(usize),
}
+
+#[derive(Copy, Clone, Debug)]
+pub enum Scene {
+ Readline,
+ Fullscreen,
+}