Implement ask_select_from_list()

This commit is contained in:
Matthias Beyer 2016-04-12 16:40:41 +02:00
parent c2e2fca8eb
commit a3f3cd3e00

View file

@ -3,9 +3,15 @@
use std::io::stdin; use std::io::stdin;
use std::io::BufRead; use std::io::BufRead;
use std::io::BufReader; use std::io::BufReader;
use std::result::Result as RResult;
use error::InteractionError;
use error::InteractionErrorKind;
use result::Result;
use regex::Regex; use regex::Regex;
use ansi_term::Colour::*; use ansi_term::Colour::*;
use interactor::*;
/// Ask the user for a Yes/No answer. Optionally provide a default value. If none is provided, this /// Ask the user for a Yes/No answer. Optionally provide a default value. If none is provided, this
/// keeps loop{}ing /// keeps loop{}ing
@ -59,7 +65,7 @@ fn ask_uint_<R: BufRead>(s: &str, default: Option<u64>, input: &mut R) -> u64 {
let mut s = String::new(); let mut s = String::new();
let _ = input.read_line(&mut s); let _ = input.read_line(&mut s);
let u : Result<u64, _> = FromStr::from_str(&s[..]); let u : RResult<u64, _> = FromStr::from_str(&s[..]);
match u { match u {
Ok(u) => { return u; }, Ok(u) => { return u; },
Err(_) => { Err(_) => {
@ -141,6 +147,11 @@ pub fn ask_string_<R: BufRead>(s: &str,
} }
} }
pub fn ask_select_from_list(list: &[&str]) -> Result<String> {
pick_from_list(default_menu_cmd().as_mut(), list, "Selection: ")
.map_err(|e| InteractionError::new(InteractionErrorKind::Unknown, Some(Box::new(e))))
}
/// Helper function to print a imag question string. The `question` argument may not contain a /// Helper function to print a imag question string. The `question` argument may not contain a
/// trailing questionmark. /// trailing questionmark.
/// ///