diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-02-27 16:36:08 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-02-27 16:36:08 -0500 |
commit | 25c8b77ba569468cddfae45f069f1c58170da475 (patch) | |
tree | 7d2e36afdac77b84dc0c7a6e47a8968ef9a39092 /src | |
parent | 68691cedbfc82f7c2a57f6aaa0f2552f8ad1f8ba (diff) | |
download | nbsh-25c8b77ba569468cddfae45f069f1c58170da475.tar.gz nbsh-25c8b77ba569468cddfae45f069f1c58170da475.zip |
these aliases are not really saving much of anything
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 1 | ||||
-rw-r--r-- | src/mutex.rs | 10 | ||||
-rw-r--r-- | src/shell/history/mod.rs | 28 | ||||
-rw-r--r-- | src/shell/history/pty.rs | 6 | ||||
-rw-r--r-- | src/shell/mod.rs | 4 |
5 files changed, 24 insertions, 25 deletions
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<T> = std::sync::Arc<tokio::sync::Mutex<T>>; -pub type Guard<T> = tokio::sync::OwnedMutexGuard<T>; - -pub fn new<T>(t: T) -> Mutex<T> { - std::sync::Arc::new(tokio::sync::Mutex::new(t)) -} - -pub fn clone<T>(m: &Mutex<T>) -> Mutex<T> { - 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<crate::mutex::Mutex<Entry>>, + entries: Vec<std::sync::Arc<tokio::sync::Mutex<Entry>>>, 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<Entry> { + pub async fn entry( + &self, + idx: usize, + ) -> tokio::sync::OwnedMutexGuard<Entry> { self.entries[idx].clone().lock_owned().await } @@ -187,7 +190,10 @@ impl History { } struct VisibleEntries { - entries: std::collections::VecDeque<(usize, crate::mutex::Guard<Entry>)>, + entries: std::collections::VecDeque<( + usize, + tokio::sync::OwnedMutexGuard<Entry>, + )>, } impl VisibleEntries { @@ -197,14 +203,18 @@ impl VisibleEntries { } } - fn add(&mut self, idx: usize, entry: crate::mutex::Guard<Entry>) { + fn add( + &mut self, + idx: usize, + entry: tokio::sync::OwnedMutexGuard<Entry>, + ) { // 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<Entry>); + type Item = (usize, tokio::sync::OwnedMutexGuard<Entry>); fn next(&mut self) -> Option<Self::Item> { self.entries.pop_front() @@ -219,7 +229,7 @@ impl std::iter::DoubleEndedIterator for VisibleEntries { fn run_commands( cmdline: String, - entry: crate::mutex::Mutex<Entry>, + entry: std::sync::Arc<tokio::sync::Mutex<Entry>>, mut env: Env, input_r: tokio::sync::mpsc::UnboundedReceiver<Vec<u8>>, 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<super::Entry>, + entry: &std::sync::Arc<tokio::sync::Mutex<super::Entry>>, input_r: tokio::sync::mpsc::UnboundedReceiver<Vec<u8>>, 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<pty_process::Pts>, - entry: crate::mutex::Mutex<super::Entry>, + entry: std::sync::Arc<tokio::sync::Mutex<super::Entry>>, input_r: tokio::sync::mpsc::UnboundedReceiver<Vec<u8>>, 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<crate::mutex::Guard<history::Entry>>, + entry: Option<tokio::sync::OwnedMutexGuard<history::Entry>>, ) -> 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<crate::mutex::Guard<history::Entry>>, + entry: Option<tokio::sync::OwnedMutexGuard<history::Entry>>, ) { self.focus = new_focus; self.hide_readline = false; |