diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-08 18:01:36 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-08 18:02:22 -0500 |
commit | 629aac44ac08f3b0d665f240038de6e70ed95533 (patch) | |
tree | 5d219e6eb9cbfd3d0b23d3d89aeab99d72238bb9 /src/shell/history/mod.rs | |
parent | dfeb1dc518af88418f324a3878a802c39272f9b2 (diff) | |
download | nbsh-629aac44ac08f3b0d665f240038de6e70ed95533.tar.gz nbsh-629aac44ac08f3b0d665f240038de6e70ed95533.zip |
refactor
Diffstat (limited to 'src/shell/history/mod.rs')
-rw-r--r-- | src/shell/history/mod.rs | 73 |
1 files changed, 45 insertions, 28 deletions
diff --git a/src/shell/history/mod.rs b/src/shell/history/mod.rs index 472269f..f3b755e 100644 --- a/src/shell/history/mod.rs +++ b/src/shell/history/mod.rs @@ -299,37 +299,54 @@ fn run_commands( } }; - for command in ast.commands() { - let pipeline = - if let crate::parse::ast::Command::Pipeline(pipeline) = - command + macro_rules! run_pipeline { + ($pipeline:expr) => { + match run_pipeline( + $pipeline.input_string(), + &pty, + &mut env, + event_w.clone(), + ) + .await { - pipeline - } else { - todo!() - }; - match run_pipeline( - pipeline.input_string(), - &pty, - &mut env, - event_w.clone(), - ) - .await - { - Ok((pipeline_status, done)) => { - env.set_status(pipeline_status); - if done { - break; + Ok((pipeline_status, done)) => { + env.set_status(pipeline_status); + if done { + break; + } + } + Err(e) => { + entry + .lock_arc() + .await + .process(format!("nbsh: {}\r\n", e).as_bytes()); + env.set_status( + async_std::process::ExitStatus::from_raw(1 << 8), + ); } } - Err(e) => { - entry - .lock_arc() - .await - .process(format!("nbsh: {}\r\n", e).as_bytes()); - env.set_status(async_std::process::ExitStatus::from_raw( - 1 << 8, - )); + }; + } + + let commands = ast.commands(); + let mut pc = 0; + while pc < commands.len() { + match &commands[pc] { + crate::parse::ast::Command::Pipeline(pipeline) => { + run_pipeline!(pipeline); + pc += 1; + } + crate::parse::ast::Command::If(_pipeline) => { + todo!(); + } + crate::parse::ast::Command::While(_pipeline) => { + todo!(); + } + crate::parse::ast::Command::For(_var, _pipeline) => { + todo!(); + } + crate::parse::ast::Command::End => { + todo!(); } } } |