diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-25 15:37:38 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-25 15:37:38 -0500 |
commit | 000d3619847673cb66c8dd84fce675386f894c75 (patch) | |
tree | 503aea5cd6b04a249f9b46d90e4ac70a164dea23 | |
parent | c6dee2a05ab5e4f069ba443f030ef9d6c6d49db5 (diff) | |
download | nbsh-000d3619847673cb66c8dd84fce675386f894c75.tar.gz nbsh-000d3619847673cb66c8dd84fce675386f894c75.zip |
refactor
-rw-r--r-- | src/state/history.rs | 65 |
1 files changed, 44 insertions, 21 deletions
diff --git a/src/state/history.rs b/src/state/history.rs index 5a3b9ab..f147c37 100644 --- a/src/state/history.rs +++ b/src/state/history.rs @@ -541,27 +541,18 @@ fn run_commands( ) { async_std::task::spawn(async move { let mut status = async_std::process::ExitStatus::from_raw(0 << 8); - 'commands: for pipeline in ast.pipelines() { - assert_eq!(pipeline.exes().len(), 1); - for exe in pipeline.exes() { - status = run_exe( - exe, - async_std::sync::Arc::clone(&entry), - input_r.clone(), - resize_r.clone(), - event_w.clone(), - ) - .await; - - // i'm not sure what exactly the expected behavior here is - - // in zsh, SIGINT kills the whole command line while SIGTERM - // doesn't, but i don't know what the precise logic is or how - // other signals are handled - if status.signal() - == Some(signal_hook::consts::signal::SIGINT) - { - break 'commands; - } + for pipeline in ast.pipelines() { + let (pipeline_status, done) = run_pipeline( + pipeline, + async_std::sync::Arc::clone(&entry), + input_r.clone(), + resize_r.clone(), + event_w.clone(), + ) + .await; + status = pipeline_status; + if done { + break; } } entry.lock_arc().await.exit_info = Some(ExitInfo::new(status)); @@ -572,6 +563,38 @@ fn run_commands( }); } +async fn run_pipeline( + pipeline: &crate::parse::Pipeline, + entry: async_std::sync::Arc<async_std::sync::Mutex<Entry>>, + 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::process::ExitStatus, bool) { + // for now + assert_eq!(pipeline.exes().len(), 1); + + let mut status = async_std::process::ExitStatus::from_raw(0 << 8); + for exe in pipeline.exes() { + status = run_exe( + exe, + async_std::sync::Arc::clone(&entry), + input_r.clone(), + resize_r.clone(), + event_w.clone(), + ) + .await; + + // i'm not sure what exactly the expected behavior here is - + // in zsh, SIGINT kills the whole command line while SIGTERM + // doesn't, but i don't know what the precise logic is or how + // other signals are handled + if status.signal() == Some(signal_hook::consts::signal::SIGINT) { + return (status, true); + } + } + (status, false) +} + async fn run_exe( exe: &crate::parse::Exe, entry: async_std::sync::Arc<async_std::sync::Mutex<Entry>>, |