From b96b4a50d7f38ac0d884f677d4e1c4172c3f19ae Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 11 Dec 2021 02:14:03 -0500 Subject: simplify also avoid releasing and reacquiring the entry lock multiple times within a single handler, to avoid time of check to time of use issues --- src/state.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/state.rs') diff --git a/src/state.rs b/src/state.rs index c030e2a..28f76ac 100644 --- a/src/state.rs +++ b/src/state.rs @@ -71,7 +71,7 @@ impl State { textmode::Key::Ctrl(b'm') => { let idx = self.focus_idx(); let focus = if let Some(idx) = idx { - self.history.running(idx).await + self.history.entry(idx).await.running() } else { true }; @@ -87,7 +87,7 @@ impl State { textmode::Key::Char(' ') => { if let Some(idx) = self.focus_idx() { self.readline - .set_input(&self.history.history_cmd(idx).await); + .set_input(&self.history.entry(idx).await.cmd()); self.set_focus(crate::action::Focus::Readline).await; } } @@ -100,14 +100,13 @@ impl State { } textmode::Key::Char('f') => { if let Some(idx) = self.focus_idx() { + let mut entry = self.history.entry(idx).await; let mut focus = crate::action::Focus::History(idx); if let crate::action::Focus::Scrolling(_) = self.focus { - self.history.set_fullscreen(idx, true).await; + entry.set_fullscreen(true); } else { - self.history.toggle_fullscreen(idx).await; - if !self.history.should_fullscreen(idx).await - && !self.history.running(idx).await - { + entry.toggle_fullscreen(); + if !entry.should_fullscreen() && !entry.running() { focus = crate::action::Focus::Scrolling(Some(idx)); } @@ -259,7 +258,7 @@ impl State { crate::action::Scene::Readline } crate::action::Focus::History(idx) => { - if self.history.should_fullscreen(idx).await { + if self.history.entry(idx).await.should_fullscreen() { crate::action::Scene::Fullscreen } else { crate::action::Scene::Readline -- cgit v1.2.3-54-g00ecf