From f0a043a080ddfe70637a26823f1ed212e5e169da Mon Sep 17 00:00:00 2001 From: "Matheus T. dos Santos" Date: Thu, 9 May 2024 20:41:46 -0300 Subject: [PATCH] feat: add quiet optional argument to scope.exec --- plugins/scope.lua | 5 +++-- src/plugin.rs | 2 ++ src/plugin_manager.rs | 4 ++-- src/process.rs | 13 ++++++++++--- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/plugins/scope.lua b/plugins/scope.lua index 3b8de03..4234873 100644 --- a/plugins/scope.lua +++ b/plugins/scope.lua @@ -49,8 +49,9 @@ scope = { sleep = function(time) coroutine.yield({ ":sleep", time }) end, - exec = function(cmd) - local _, stdout, stderr = coroutine.yield({ ":exec", cmd }) + exec = function(cmd, quiet) + quiet = quiet or false + local _, stdout, stderr = coroutine.yield({ ":exec", cmd, quiet }) return stdout, stderr end } diff --git a/src/plugin.rs b/src/plugin.rs index e200206..690ed11 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -36,6 +36,7 @@ pub enum PluginRequest { }, Exec { cmd: String, + quiet: bool, }, } @@ -150,6 +151,7 @@ impl<'a> TryFrom> for PluginRequest { } ":exec" => Ok(PluginRequest::Exec { cmd: value.get(2).map_err(|err| err.to_string())?, + quiet: value.get(3).map_err(|err| err.to_string())?, }), _ => Err("Unknown function".to_string()), } diff --git a/src/plugin_manager.rs b/src/plugin_manager.rs index 0ade13a..7336344 100644 --- a/src/plugin_manager.rs +++ b/src/plugin_manager.rs @@ -300,7 +300,7 @@ impl PluginManager { } } PluginRequest::Sleep { time } => tokio::time::sleep(time).await, - PluginRequest::Exec { cmd } => match origin { + PluginRequest::Exec { cmd, quiet } => match origin { ExecutionOrigin::SerialRx => { Plugin::eprintln( text_view, @@ -313,7 +313,7 @@ impl PluginManager { flags.has_process_running.store(true, Ordering::SeqCst); let res = Some( process_runner - .run(plugin_name, cmd, flags.stop_process.clone()) + .run(plugin_name, cmd, quiet, flags.stop_process.clone()) .await .unwrap(), ); diff --git a/src/process.rs b/src/process.rs index fa9e2f9..4b59f42 100644 --- a/src/process.rs +++ b/src/process.rs @@ -28,9 +28,12 @@ impl ProcessRunner { &self, plugin_name: String, cmd: String, + quiet: bool, stop_process_flag: Arc, ) -> Result { - Plugin::println(self.text_view.clone(), plugin_name.clone(), cmd.clone()).await; + if !quiet { + Plugin::println(self.text_view.clone(), plugin_name.clone(), cmd.clone()).await; + } let mut child = if cfg!(target_os = "windows") { Command::new("cmd") @@ -67,7 +70,9 @@ impl ProcessRunner { } buffer.push(line.clone()); - Plugin::println(text_view2.clone(), plugin_name.clone(), line.clone()).await; + if !quiet { + Plugin::println(text_view2.clone(), plugin_name.clone(), line.clone()).await; + } } buffer @@ -84,7 +89,9 @@ impl ProcessRunner { } buffer.push(line.clone()); - Plugin::eprintln(text_view3.clone(), plugin_name2.clone(), line).await; + if !quiet { + Plugin::eprintln(text_view3.clone(), plugin_name2.clone(), line).await; + } } buffer