aboutsummaryrefslogtreecommitdiff
path: root/src/backends/dialog.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-12-10 20:09:59 +0100
committerRobin Krahl <robin.krahl@ireas.org>2019-12-10 20:09:59 +0100
commitaa8148b958daac4b35173a1d28806b2fdc8609bd (patch)
treed3c438f91a911f8e4bd0fb96dc833edaac4f21e6 /src/backends/dialog.rs
parent10462c2c9f4ae2ffd3c32dd4628e0052067c15fa (diff)
parent202c49a327b7a3dc3bfa199da2ac7484ee105f65 (diff)
downloaddialog-rs-aa8148b958daac4b35173a1d28806b2fdc8609bd.tar.gz
dialog-rs-aa8148b958daac4b35173a1d28806b2fdc8609bd.tar.bz2
Merge branch 'release-v0.3.0'HEADmaster
Diffstat (limited to 'src/backends/dialog.rs')
-rw-r--r--src/backends/dialog.rs47
1 files changed, 29 insertions, 18 deletions
diff --git a/src/backends/dialog.rs b/src/backends/dialog.rs
index e681caf..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.
///
@@ -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<Dialog> 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(())
@@ -111,19 +117,17 @@ fn get_choice(status: process::ExitStatus) -> Result<Choice> {
fn get_stderr(output: process::Output) -> Result<Option<String>> {
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)))
}
}
@@ -156,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<Option<String>> {
+ 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)
+ }
}