From 25c8b77ba569468cddfae45f069f1c58170da475 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 27 Feb 2022 16:36:08 -0500 Subject: these aliases are not really saving much of anything --- src/main.rs | 1 - src/mutex.rs | 10 ---------- src/shell/history/mod.rs | 28 +++++++++++++++++++--------- src/shell/history/pty.rs | 6 +++--- src/shell/mod.rs | 4 ++-- 5 files changed, 24 insertions(+), 25 deletions(-) delete mode 100644 src/mutex.rs (limited to 'src') diff --git a/src/main.rs b/src/main.rs index f8db695..1e9d70f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,6 @@ mod env; mod format; mod info; -mod mutex; mod parse; mod prelude; mod runner; diff --git a/src/mutex.rs b/src/mutex.rs deleted file mode 100644 index e49df9c..0000000 --- a/src/mutex.rs +++ /dev/null @@ -1,10 +0,0 @@ -pub type Mutex = std::sync::Arc>; -pub type Guard = tokio::sync::OwnedMutexGuard; - -pub fn new(t: T) -> Mutex { - std::sync::Arc::new(tokio::sync::Mutex::new(t)) -} - -pub fn clone(m: &Mutex) -> Mutex { - std::sync::Arc::clone(m) -} diff --git a/src/shell/history/mod.rs b/src/shell/history/mod.rs index e7202be..18231af 100644 --- a/src/shell/history/mod.rs +++ b/src/shell/history/mod.rs @@ -6,7 +6,7 @@ mod pty; pub struct History { size: (u16, u16), - entries: Vec>, + entries: Vec>>, scroll_pos: usize, } @@ -91,16 +91,16 @@ impl History { let (input_w, input_r) = tokio::sync::mpsc::unbounded_channel(); let (resize_w, resize_r) = tokio::sync::mpsc::unbounded_channel(); - let entry = crate::mutex::new(Entry::new( + let entry = std::sync::Arc::new(tokio::sync::Mutex::new(Entry::new( cmdline.to_string(), env.clone(), self.size, input_w, resize_w, - )); + ))); run_commands( cmdline.to_string(), - crate::mutex::clone(&entry), + std::sync::Arc::clone(&entry), env.clone(), input_r, resize_r, @@ -111,7 +111,10 @@ impl History { Ok(self.entries.len() - 1) } - pub async fn entry(&self, idx: usize) -> crate::mutex::Guard { + pub async fn entry( + &self, + idx: usize, + ) -> tokio::sync::OwnedMutexGuard { self.entries[idx].clone().lock_owned().await } @@ -187,7 +190,10 @@ impl History { } struct VisibleEntries { - entries: std::collections::VecDeque<(usize, crate::mutex::Guard)>, + entries: std::collections::VecDeque<( + usize, + tokio::sync::OwnedMutexGuard, + )>, } impl VisibleEntries { @@ -197,14 +203,18 @@ impl VisibleEntries { } } - fn add(&mut self, idx: usize, entry: crate::mutex::Guard) { + fn add( + &mut self, + idx: usize, + entry: tokio::sync::OwnedMutexGuard, + ) { // push_front because we are adding them in reverse order self.entries.push_front((idx, entry)); } } impl std::iter::Iterator for VisibleEntries { - type Item = (usize, crate::mutex::Guard); + type Item = (usize, tokio::sync::OwnedMutexGuard); fn next(&mut self) -> Option { self.entries.pop_front() @@ -219,7 +229,7 @@ impl std::iter::DoubleEndedIterator for VisibleEntries { fn run_commands( cmdline: String, - entry: crate::mutex::Mutex, + entry: std::sync::Arc>, mut env: Env, input_r: tokio::sync::mpsc::UnboundedReceiver>, resize_r: tokio::sync::mpsc::UnboundedReceiver<(u16, u16)>, diff --git a/src/shell/history/pty.rs b/src/shell/history/pty.rs index e96da41..499ccc6 100644 --- a/src/shell/history/pty.rs +++ b/src/shell/history/pty.rs @@ -8,7 +8,7 @@ pub struct Pty { impl Pty { pub fn new( size: (u16, u16), - entry: &crate::mutex::Mutex, + entry: &std::sync::Arc>, input_r: tokio::sync::mpsc::UnboundedReceiver>, resize_r: tokio::sync::mpsc::UnboundedReceiver<(u16, u16)>, event_w: crate::shell::event::Writer, @@ -22,7 +22,7 @@ impl Pty { tokio::task::spawn(pty_task( pty, std::sync::Arc::clone(&pts), - crate::mutex::clone(entry), + std::sync::Arc::clone(entry), input_r, resize_r, close_r, @@ -49,7 +49,7 @@ async fn pty_task( // take the pts here just to ensure that we don't close it before this // task finishes, otherwise the read call can return EIO _pts: std::sync::Arc, - entry: crate::mutex::Mutex, + entry: std::sync::Arc>, input_r: tokio::sync::mpsc::UnboundedReceiver>, resize_r: tokio::sync::mpsc::UnboundedReceiver<(u16, u16)>, close_r: tokio::sync::mpsc::UnboundedReceiver<()>, diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 88eb63e..68025f0 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -559,7 +559,7 @@ impl Shell { async fn default_scene( &self, focus: Focus, - entry: Option>, + entry: Option>, ) -> Scene { match focus { Focus::Readline | Focus::Scrolling(_) => Scene::Readline, @@ -581,7 +581,7 @@ impl Shell { async fn set_focus( &mut self, new_focus: Focus, - entry: Option>, + entry: Option>, ) { self.focus = new_focus; self.hide_readline = false; -- cgit v1.2.3-54-g00ecf