aboutsummaryrefslogtreecommitdiff
path: root/src/backends/stdio.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/stdio.rs
parent10462c2c9f4ae2ffd3c32dd4628e0052067c15fa (diff)
parent202c49a327b7a3dc3bfa199da2ac7484ee105f65 (diff)
downloaddialog-rs-master.tar.gz
dialog-rs-master.tar.bz2
Merge branch 'release-v0.3.0'HEADmaster
Diffstat (limited to 'src/backends/stdio.rs')
-rw-r--r--src/backends/stdio.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/backends/stdio.rs b/src/backends/stdio.rs
index 6838ef1..627714a 100644
--- a/src/backends/stdio.rs
+++ b/src/backends/stdio.rs
@@ -3,19 +3,19 @@
use std::io::{self, Write};
-use crate::{Choice, Input, Message, Password, Question, Result};
+use crate::{Choice, FileSelection, Input, Message, Password, Question, Result};
/// The fallback backend using standard input and output.
///
/// This backend is intended as a fallback backend to use if no other backend is available. The
/// dialogs are printed to the standard output and user input is read from the standard input.
-#[derive(Debug)]
+#[derive(Debug, Default)]
pub struct Stdio {}
impl Stdio {
/// Creates a new `Stdio` instance.
pub fn new() -> Stdio {
- Stdio {}
+ Default::default()
}
}
@@ -35,7 +35,7 @@ fn print_title(title: &Option<String>) {
fn read_input() -> Result<String> {
let mut input = String::new();
io::stdin().read_line(&mut input)?;
- Ok(input.trim_end_matches("\n").to_string())
+ Ok(input.trim_end_matches('\n').to_string())
}
fn parse_choice(input: &str) -> Choice {
@@ -86,4 +86,17 @@ impl super::Backend for Stdio {
io::stdout().flush()?;
Ok(parse_choice(&read_input()?))
}
+
+ fn show_file_selection(&self, file_selection: &FileSelection) -> Result<Option<String>> {
+ let dir = file_selection.path_to_string().ok_or("path not valid")?;
+ print_title(&file_selection.title);
+ print!("{} [{}]: ", file_selection.text, dir);
+ io::stdout().flush()?;
+ let result = read_input()?;
+ if result.starts_with('/') {
+ Ok(Some(result))
+ } else {
+ Ok(Some(dir + &result))
+ }
+ }
}