From 5846b64020918fb376d71e07e835ca442a5dde63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 26 Jan 2019 17:32:48 +1300 Subject: [PATCH] [run] Further dry the ExecHandler --- src/process.rs | 12 ++---------- src/run.rs | 38 +++++++++++--------------------------- 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/src/process.rs b/src/process.rs index 31b91da..22d1656 100644 --- a/src/process.rs +++ b/src/process.rs @@ -82,11 +82,7 @@ mod imp { #[allow(unknown_lints)] #[allow(mutex_atomic)] impl Process { - pub fn new( - cmd: &Vec, - updated_paths: &[PathOp], - no_shell: bool, - ) -> Result { + pub fn new(cmd: &Vec, updated_paths: &[PathOp], no_shell: bool) -> Result { use nix::unistd::*; use std::os::unix::process::CommandExt; @@ -203,11 +199,7 @@ mod imp { } impl Process { - pub fn new( - cmd: &Vec, - updated_paths: &[PathOp], - no_shell: bool, - ) -> Result { + pub fn new(cmd: &Vec, updated_paths: &[PathOp], no_shell: bool) -> Result { use std::os::windows::io::IntoRawHandle; use std::os::windows::process::CommandExt; diff --git a/src/run.rs b/src/run.rs index 2e25306..0ea0734 100644 --- a/src/run.rs +++ b/src/run.rs @@ -149,12 +149,13 @@ pub struct ExecHandler { impl ExecHandler { fn spawn(&mut self, ops: &[PathOp]) -> Result<()> { + if self.args.clear_screen { + clear_screen(); + } + + debug!("Launching child process"); let mut guard = self.child_process.write()?; - *guard = Some(process::spawn( - &self.args.cmd, - ops, - self.args.no_shell, - )?); + *guard = Some(process::spawn(&self.args.cmd, ops, self.args.no_shell)?); Ok(()) } @@ -189,7 +190,11 @@ impl Handler for ExecHandler { // Only returns Err() on lock poisoning. fn on_manual(&mut self) -> Result { - self.spawn(&[]).and(Ok(true)) + let cls = self.args.clear_screen; + self.args.clear_screen = false; + self.spawn(&[])?; + self.args.clear_screen = cls; + Ok(true) } // Only returns Err() on lock poisoning. @@ -208,13 +213,6 @@ impl Handler for ExecHandler { // Send specified signal to the child, wait for it to exit, then run the command again (true, true) => { signal_process(&self.child_process, self.signal, true); - - // Launch child process - if self.args.clear_screen { - clear_screen(); - } - - debug!("Launching child process"); self.spawn(ops)?; } @@ -223,13 +221,6 @@ impl Handler for ExecHandler { (true, false) => { let sigterm = signal::new(Some("SIGTERM".into())); signal_process(&self.child_process, sigterm, true); - - // Launch child process - if self.args.clear_screen { - clear_screen(); - } - - debug!("Launching child process"); self.spawn(ops)?; } @@ -241,13 +232,6 @@ impl Handler for ExecHandler { // Make sure the previous run was ended, then run the command again (false, false) => { signal_process(&self.child_process, None, true); - - // Launch child process - if self.args.clear_screen { - clear_screen(); - } - - debug!("Launching child process"); self.spawn(ops)?; } }