From 747da41fd3f192038c2e3194b4de041f7969f7a8 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 10 Nov 2021 13:14:44 -0500 Subject: simplify --- src/history.rs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'src/history.rs') diff --git a/src/history.rs b/src/history.rs index 00ad39a..bf46693 100644 --- a/src/history.rs +++ b/src/history.rs @@ -3,13 +3,13 @@ use pty_process::Command as _; use textmode::Textmode as _; pub struct History { - entries: Vec>>, - action: async_std::channel::Sender, + entries: Vec>, + action: async_std::channel::Sender, } impl History { pub fn new( - action: async_std::channel::Sender, + action: async_std::channel::Sender, ) -> Self { Self { entries: vec![], @@ -24,8 +24,9 @@ impl History { let child = process .spawn_pty(Some(&pty_process::Size::new(24, 80))) .unwrap(); - let entry = async_std::sync::Arc::new(async_std::sync::Mutex::new( - HistoryEntry::new(cmd, child.id().try_into().unwrap()), + let entry = crate::util::mutex(HistoryEntry::new( + cmd, + child.id().try_into().unwrap(), )); let task_entry = async_std::sync::Arc::clone(&entry); let task_action = self.action.clone(); @@ -42,29 +43,27 @@ impl History { } task_entry.lock_arc().await.running = false; task_action - .send(crate::nbsh::Action::UpdateFocus( - crate::nbsh::InputSource::Repl, + .send(crate::state::Action::UpdateFocus( + crate::state::Focus::Readline, )) .await .unwrap(); - task_action - .send(crate::nbsh::Action::Render) - .await - .unwrap(); break; } } - task_action.send(crate::nbsh::Action::Render).await.unwrap(); + task_action + .send(crate::state::Action::Render) + .await + .unwrap(); } }); self.entries.push(entry); self.action - .send(crate::nbsh::Action::UpdateFocus( - crate::nbsh::InputSource::History(self.entries.len() - 1), + .send(crate::state::Action::UpdateFocus( + crate::state::Focus::History(self.entries.len() - 1), )) .await .unwrap(); - self.action.send(crate::nbsh::Action::Render).await.unwrap(); Ok(self.entries.len() - 1) } @@ -81,8 +80,8 @@ impl History { } textmode::Key::Ctrl(b'z') => { self.action - .send(crate::nbsh::Action::UpdateFocus( - crate::nbsh::InputSource::Repl, + .send(crate::state::Action::UpdateFocus( + crate::state::Focus::Readline, )) .await .unwrap(); -- cgit v1.2.3-54-g00ecf