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/stdio.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/backends/stdio.rs') diff --git a/src/backends/stdio.rs b/src/backends/stdio.rs index 6838ef1..4e4c8ec 100644 --- a/src/backends/stdio.rs +++ b/src/backends/stdio.rs @@ -35,7 +35,7 @@ fn print_title(title: &Option) { fn read_input() -> Result { 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 { -- 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/stdio.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/backends/stdio.rs') diff --git a/src/backends/stdio.rs b/src/backends/stdio.rs index 4e4c8ec..9a153df 100644 --- a/src/backends/stdio.rs +++ b/src/backends/stdio.rs @@ -9,13 +9,13 @@ use crate::{Choice, Input, Message, Password, Question, Result}; /// /// 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() } } -- 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/stdio.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/backends/stdio.rs') 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> { + 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)) + } + } } -- cgit v1.2.1