diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-02 19:27:51 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-02 19:27:51 -0500 |
commit | 702d51e6c3cd3122579ee3cdf0b52bfba253ed2a (patch) | |
tree | 8174df9d736ae3b44c7fbdf48a53439664ecef29 /src | |
parent | cc34cb675a53adeabf60d9687c1044780a8431a3 (diff) | |
download | nbsh-702d51e6c3cd3122579ee3cdf0b52bfba253ed2a.tar.gz nbsh-702d51e6c3cd3122579ee3cdf0b52bfba253ed2a.zip |
simplify
Diffstat (limited to 'src')
-rw-r--r-- | src/state/history/mod.rs | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/state/history/mod.rs b/src/state/history/mod.rs index d2eb17c..288d217 100644 --- a/src/state/history/mod.rs +++ b/src/state/history/mod.rs @@ -97,14 +97,13 @@ impl History { let entry = async_std::sync::Arc::new(async_std::sync::Mutex::new( Entry::new(Ok(ast.clone()), self.size, input_w, resize_w), )); - let pty = - pty::Pty::new(self.size, &entry, input_r, resize_r, event_w)?; - run_commands( ast.clone(), - pty, async_std::sync::Arc::clone(&entry), ProcessEnv::new(), + input_r, + resize_r, + event_w, ); self.entries.push(entry); @@ -564,11 +563,33 @@ impl ProcessEnv { fn run_commands( ast: crate::parse::Commands, - pty: pty::Pty, entry: async_std::sync::Arc<async_std::sync::Mutex<Entry>>, mut env: ProcessEnv, + input_r: async_std::channel::Receiver<Vec<u8>>, + resize_r: async_std::channel::Receiver<(u16, u16)>, + event_w: async_std::channel::Sender<crate::event::Event>, ) { async_std::task::spawn(async move { + let pty = match pty::Pty::new( + entry.lock_arc().await.vt.screen().size(), + &entry, + input_r, + resize_r, + event_w, + ) { + Ok(pty) => pty, + Err(e) => { + let mut entry = entry.lock_arc().await; + entry.vt.process( + format!("nbsh: failed to allocate pty: {}", e).as_bytes(), + ); + entry.exit_info = Some(ExitInfo::new( + async_std::process::ExitStatus::from_raw(1 << 8), + )); + return; + } + }; + for pipeline in ast.pipelines() { let (pipeline_status, done) = run_pipeline(pipeline, &pty, &env).await; @@ -579,6 +600,7 @@ fn run_commands( } entry.lock_arc().await.exit_info = Some(ExitInfo::new(*env.latest_status())); + pty.close().await; }); } |