From 9273f3f45f7418e87b6e53baef78612ef0d6c5e7 Mon Sep 17 00:00:00 2001 From: Stephan Sokolow Date: Thu, 24 Oct 2019 20:44:39 -0400 Subject: Fix clippy complaints that don't change the semantics (Clippy also complains about `new()` without `impl Default`) --- src/backends/dialog.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/backends/dialog.rs') diff --git a/src/backends/dialog.rs b/src/backends/dialog.rs index e681caf..85b0294 100644 --- a/src/backends/dialog.rs +++ b/src/backends/dialog.rs @@ -111,19 +111,17 @@ fn get_choice(status: process::ExitStatus) -> Result { fn get_stderr(output: process::Output) -> Result> { if output.status.success() { String::from_utf8(output.stderr) - .map(|s| Some(s)) - .map_err(|err| Error::from(err)) - } else { - if let Some(code) = output.status.code() { - match code { - 0 => Ok(None), - 1 => Ok(None), - 255 => Ok(None), - _ => Err(Error::from(("dialog", output.status))), - } - } else { - Err(Error::from(("dialog", output.status))) + .map(Some) + .map_err(Error::from) + } else if let Some(code) = output.status.code() { + match code { + 0 => Ok(None), + 1 => Ok(None), + 255 => Ok(None), + _ => Err(Error::from(("dialog", output.status))), } + } else { + Err(Error::from(("dialog", output.status))) } } -- cgit v1.2.1 From 0970381271bd07f020a888b027653ca627e8655c Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 27 Oct 2019 10:55:30 +0000 Subject: Implement Default for all backend structs This fixes the clippy warning new_without_default [0]. [0] https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default --- src/backends/dialog.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/backends/dialog.rs') diff --git a/src/backends/dialog.rs b/src/backends/dialog.rs index 85b0294..8061d98 100644 --- a/src/backends/dialog.rs +++ b/src/backends/dialog.rs @@ -19,11 +19,7 @@ pub struct Dialog { impl Dialog { /// Creates a new `Dialog` instance without configuration. pub fn new() -> Dialog { - Dialog { - backtitle: None, - height: "0".to_string(), - width: "0".to_string(), - } + Default::default() } /// Sets the backtitle for the dialog boxes. @@ -87,6 +83,16 @@ impl AsRef for Dialog { } } +impl Default for Dialog { + fn default() -> Self { + Dialog { + backtitle: None, + height: "0".to_string(), + width: "0".to_string(), + } + } +} + fn require_success(status: process::ExitStatus) -> Result<()> { if status.success() { Ok(()) -- cgit v1.2.1 From 2f3e2b5474834e3d733edf09b831c5607d451f49 Mon Sep 17 00:00:00 2001 From: Reyk Floeter Date: Tue, 10 Dec 2019 15:24:36 +0000 Subject: Add FileSelection dialog type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds the FileSelection struct representing a file selection dialog. It can be displayed using the backend’s show_file_selection function. Currently, we only support file open dialogs (i. e. choosing an existing file). Support for save dialogs should be added in the future. --- src/backends/dialog.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/backends/dialog.rs') diff --git a/src/backends/dialog.rs b/src/backends/dialog.rs index 8061d98..668cf57 100644 --- a/src/backends/dialog.rs +++ b/src/backends/dialog.rs @@ -3,7 +3,7 @@ use std::process; -use crate::{Choice, Error, Input, Message, Password, Question, Result}; +use crate::{Choice, Error, FileSelection, Input, Message, Password, Question, Result}; /// The `dialog` backend. /// @@ -160,4 +160,11 @@ impl super::Backend for Dialog { self.execute(args, vec![], &question.title) .and_then(|output| get_choice(output.status)) } + + fn show_file_selection(&self, file_selection: &FileSelection) -> Result> { + let dir = file_selection.path_to_string().ok_or("path not valid")?; + let args = vec!["--fselect", &dir]; + self.execute(args, vec![], &file_selection.title) + .and_then(get_stderr) + } } -- cgit v1.2.1