diff options
author | Reyk Floeter <reyk.floeter@googlemail.com> | 2019-12-10 15:24:36 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-12-10 19:56:09 +0100 |
commit | 2f3e2b5474834e3d733edf09b831c5607d451f49 (patch) | |
tree | 4b94e0e6874ae300f595e8dd9bffd06aec867543 /src/backends/stdio.rs | |
parent | 3b76a0a46ce38eef7fe3e5a969cec6ffee47f227 (diff) | |
download | dialog-rs-2f3e2b5474834e3d733edf09b831c5607d451f49.tar.gz dialog-rs-2f3e2b5474834e3d733edf09b831c5607d451f49.tar.bz2 |
Add FileSelection dialog type
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.
Diffstat (limited to 'src/backends/stdio.rs')
-rw-r--r-- | src/backends/stdio.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/backends/stdio.rs b/src/backends/stdio.rs index 9a153df..627714a 100644 --- a/src/backends/stdio.rs +++ b/src/backends/stdio.rs @@ -3,7 +3,7 @@ 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. /// @@ -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)) + } + } } |