diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-08 19:53:21 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-08 19:53:21 -0500 |
commit | 5dfd1f7a7734038eed310729e907313e7b499d68 (patch) | |
tree | eb12a29765308b0987012d71ad91e092dacbe036 /src/shell | |
parent | 28953168e80183fe11d2031369b48022eefd37e5 (diff) | |
download | nbsh-5dfd1f7a7734038eed310729e907313e7b499d68.tar.gz nbsh-5dfd1f7a7734038eed310729e907313e7b499d68.zip |
cleanups
Diffstat (limited to 'src/shell')
-rw-r--r-- | src/shell/event.rs | 4 | ||||
-rw-r--r-- | src/shell/history/mod.rs | 54 | ||||
-rw-r--r-- | src/shell/history/pty.rs | 6 | ||||
-rw-r--r-- | src/shell/mod.rs | 4 |
4 files changed, 27 insertions, 41 deletions
diff --git a/src/shell/event.rs b/src/shell/event.rs index 0343cdb..52b7acf 100644 --- a/src/shell/event.rs +++ b/src/shell/event.rs @@ -17,12 +17,12 @@ impl Reader { pub fn new( input: async_std::channel::Receiver<Event>, ) -> async_std::sync::Arc<Self> { - let this = std::sync::Arc::new(Self { + let this = async_std::sync::Arc::new(Self { pending: async_std::sync::Mutex::new(Pending::new()), cvar: async_std::sync::Condvar::new(), }); { - let this = std::sync::Arc::clone(&this); + let this = async_std::sync::Arc::clone(&this); async_std::task::spawn(async move { while let Ok(event) = input.recv().await { this.new_event(Some(event)).await; diff --git a/src/shell/history/mod.rs b/src/shell/history/mod.rs index 2f84c37..b2ad9d0 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<async_std::sync::Arc<async_std::sync::Mutex<Entry>>>, + entries: Vec<crate::mutex::Mutex<Entry>>, scroll_pos: usize, } @@ -95,18 +95,16 @@ impl History { let (input_w, input_r) = async_std::channel::unbounded(); let (resize_w, resize_r) = async_std::channel::unbounded(); - let entry = async_std::sync::Arc::new(async_std::sync::Mutex::new( - Entry::new( - ast.input_string().to_string(), - env.clone(), - self.size, - input_w, - resize_w, - ), + let entry = crate::mutex::new(Entry::new( + ast.input_string().to_string(), + env.clone(), + self.size, + input_w, + resize_w, )); run_commands( ast, - async_std::sync::Arc::clone(&entry), + crate::mutex::clone(&entry), env.clone(), input_r, resize_r, @@ -132,16 +130,14 @@ impl History { resize_r.close(); let err_str = format!("{}", e); - let entry = async_std::sync::Arc::new(async_std::sync::Mutex::new( - Entry::new( - e.into_input(), - env.clone(), - self.size, - input_w, - resize_w, - ), + let entry = crate::mutex::new(Entry::new( + e.into_input(), + env.clone(), + self.size, + input_w, + resize_w, )); - self.entries.push(async_std::sync::Arc::clone(&entry)); + self.entries.push(crate::mutex::clone(&entry)); let mut entry = entry.lock_arc().await; entry.process(err_str.replace('\n', "\r\n").as_bytes()); @@ -152,10 +148,7 @@ impl History { Ok(self.entries.len() - 1) } - pub async fn entry( - &self, - idx: usize, - ) -> async_std::sync::MutexGuardArc<Entry> { + pub async fn entry(&self, idx: usize) -> crate::mutex::Guard<Entry> { self.entries[idx].lock_arc().await } @@ -231,10 +224,7 @@ impl History { } struct VisibleEntries { - entries: std::collections::VecDeque<( - usize, - async_std::sync::MutexGuardArc<Entry>, - )>, + entries: std::collections::VecDeque<(usize, crate::mutex::Guard<Entry>)>, } impl VisibleEntries { @@ -244,18 +234,14 @@ impl VisibleEntries { } } - fn add( - &mut self, - idx: usize, - entry: async_std::sync::MutexGuardArc<Entry>, - ) { + fn add(&mut self, idx: usize, entry: crate::mutex::Guard<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, async_std::sync::MutexGuardArc<Entry>); + type Item = (usize, crate::mutex::Guard<Entry>); fn next(&mut self) -> Option<Self::Item> { self.entries.pop_front() @@ -325,7 +311,7 @@ enum Frame { fn run_commands( ast: crate::parse::ast::Commands, - entry: async_std::sync::Arc<async_std::sync::Mutex<Entry>>, + entry: crate::mutex::Mutex<Entry>, mut env: Env, input_r: async_std::channel::Receiver<Vec<u8>>, resize_r: async_std::channel::Receiver<(u16, u16)>, diff --git a/src/shell/history/pty.rs b/src/shell/history/pty.rs index edf06c2..0fe0942 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: &async_std::sync::Arc<async_std::sync::Mutex<super::Entry>>, + entry: &crate::mutex::Mutex<super::Entry>, input_r: async_std::channel::Receiver<Vec<u8>>, resize_r: async_std::channel::Receiver<(u16, u16)>, event_w: async_std::channel::Sender<Event>, @@ -21,7 +21,7 @@ impl Pty { async_std::task::spawn(pty_task( async_std::sync::Arc::clone(&pty), - async_std::sync::Arc::clone(entry), + crate::mutex::clone(entry), input_r, resize_r, close_r, @@ -45,7 +45,7 @@ impl Pty { async fn pty_task( pty: async_std::sync::Arc<pty_process::Pty>, - entry: async_std::sync::Arc<async_std::sync::Mutex<super::Entry>>, + entry: crate::mutex::Mutex<super::Entry>, input_r: async_std::channel::Receiver<Vec<u8>>, resize_r: async_std::channel::Receiver<(u16, u16)>, close_r: async_std::channel::Receiver<()>, diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 7a16651..04cf385 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -487,7 +487,7 @@ impl Shell { async fn default_scene( &self, focus: Focus, - entry: Option<async_std::sync::MutexGuardArc<history::Entry>>, + entry: Option<crate::mutex::Guard<history::Entry>>, ) -> Scene { match focus { Focus::Readline | Focus::Scrolling(_) => Scene::Readline, @@ -509,7 +509,7 @@ impl Shell { async fn set_focus( &mut self, new_focus: Focus, - entry: Option<async_std::sync::MutexGuardArc<history::Entry>>, + entry: Option<crate::mutex::Guard<history::Entry>>, ) { self.focus = new_focus; self.hide_readline = false; |