diff options
Diffstat (limited to 'src/run')
| -rw-r--r-- | src/run/builtin.rs | 4 | ||||
| -rw-r--r-- | src/run/mod.rs | 37 |
2 files changed, 27 insertions, 14 deletions
diff --git a/src/run/builtin.rs b/src/run/builtin.rs index cfaef1e..f085005 100644 --- a/src/run/builtin.rs +++ b/src/run/builtin.rs @@ -120,9 +120,9 @@ impl Builtin for re { } fn special(&mut self, session: Arc<Mutex<Session>>, _args: &[BString]) { - session.lock().unwrap().raw.disable(); + session.lock().unwrap().raw_disable(); crate::reload::begin_reload(); - session.lock().unwrap().raw.enable(); // something went wrong, let's restore raw mode + session.lock().unwrap().raw_enable(); // something went wrong, let's restore raw mode } fn io( diff --git a/src/run/mod.rs b/src/run/mod.rs index 885261b..7e575ce 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -95,12 +95,12 @@ pub struct Executor { expand_commands: bool, } -struct SpawnedPipeline { +pub struct SpawnedPipeline { executors: Vec<SpawnedCmd>, cancel: Vec<Canceler>, } -enum SpawnedCmd { +pub enum SpawnedCmd { Builtin(ThreadWaiter<Result<(), BuiltinError>>), Fun(ThreadWaiter<Result<(), ExecError>>), Child(ChildWaiter), @@ -135,7 +135,7 @@ impl IsSuccessful for Result<(), ExecError> { } impl SpawnedCmd { - fn join(self) -> Result<(), ExecError> { + pub fn join(self) -> Result<(), ExecError> { match self { SpawnedCmd::Builtin(handle) => { handle.into_inner().join().map_err(|_| ExecError::Panic)?? @@ -171,7 +171,7 @@ impl SpawnedCmd { } /// returns whether the spawned command is already joined - fn join_timeout(&mut self, timeout_ms: u16) -> bool { + pub fn join_timeout(&mut self, timeout_ms: u16) -> bool { match self { SpawnedCmd::Builtin(tw) => tw.try_join(timeout_ms), SpawnedCmd::Fun(tw) => tw.try_join(timeout_ms), @@ -185,7 +185,7 @@ impl SpawnedCmd { } } - fn cancel(&mut self) { + pub fn cancel(&mut self) { match self { SpawnedCmd::Pipeline(pipes) => { for c in pipes.cancel.iter_mut() { @@ -226,6 +226,14 @@ impl Executor { } } + pub fn new(se: Arc<Mutex<Session>>) -> Self { + Self { + se, + args: None, + expand_commands: true, + } + } + fn spawn_cmd( &mut self, cmd: CommandKind, @@ -436,6 +444,15 @@ impl Executor { }); SpawnedCmd::Fun(handle) } + + pub fn execute_script( + &mut self, + s: parse::Script, + stdin: InputReader, + stdout: OutputWriter, + ) -> SpawnedCmd { + self.execute_block(parse::Block { commands: s.stmts }, stdin, stdout) + } } impl parse::Expander for Executor { @@ -559,11 +576,7 @@ impl Aliases { } fn exec(se: Arc<Mutex<Session>>, ast: Ast<PreExpansion>) -> Result<(), ExecError> { - let mut exec = Executor { - se: se.clone(), - args: None, - expand_commands: true, - }; + let mut exec = Executor::new(se.clone()); let ast = ast.expand(&mut exec)?; let (stdin, c1) = InputReader::new(Input::Stdin); let (stdout, c2) = OutputWriter::new(Output::Stdout); @@ -587,9 +600,9 @@ pub fn run_quiet( } pub fn run(se: Arc<Mutex<Session>>, parsed: Ast<PreExpansion>) { - se.lock().unwrap().raw.disable(); + se.lock().unwrap().raw_disable(); let result = exec(se.clone(), parsed); - se.lock().unwrap().raw.enable(); + se.lock().unwrap().raw_enable(); if se.lock().unwrap().loud { let status_string = match result { |
