From 9fc28c2099b50484a4b3154f64f764904d57334e Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 8 Jan 2019 02:21:32 +0000 Subject: backends/Dialog: Add support for output handling dialog(1) uses stdin to display the dialog boxes and prints output to stderr (if applicable). This patch changes the command invocation in the Dialog backend to capture stderr. stdin and stdout are inherited from the main process so that dialog can display the dialog boxes and receive user input. --- src/backends/dialog.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/backends/dialog.rs b/src/backends/dialog.rs index b448c05..d50be43 100644 --- a/src/backends/dialog.rs +++ b/src/backends/dialog.rs @@ -28,14 +28,18 @@ impl Dialog { } } - fn execute(&self, args: Vec<&str>) -> Result { + fn execute(&self, args: Vec<&str>) -> Result { let mut args = args; if let Some(ref backtitle) = self.backtitle { args.insert(0, "--backtitle"); args.insert(1, backtitle); } println!("{:?}", args); - process::Command::new("dialog").args(args).status() + process::Command::new("dialog") + .args(args) + .stdin(process::Stdio::inherit()) + .stdout(process::Stdio::inherit()) + .output() } /// Sets the backtitle for the dialog boxes. @@ -61,7 +65,7 @@ impl Dialog { self.width = width.to_string(); } - fn show_box(&self, args: Vec<&str>, title: &Option) -> Result { + fn show_box(&self, args: Vec<&str>, title: &Option) -> Result { let mut args = args; if let Some(ref title) = title { args.insert(0, "--title"); @@ -85,6 +89,7 @@ impl super::Backend for Dialog { fn show_message(&self, message: &Message) -> Result<()> { let args = vec!["--msgbox", &message.text]; self.show_box(args, &message.title) - .and_then(require_success) + .and_then(|output| require_success(output.status)) + .map(|_| ()) } } -- cgit v1.2.1