summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-05-19 12:34:51 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-05-25 10:43:24 +0200
commit1c6b02454c5617c6c0b99a9008b76917db3fc699 (patch)
tree01e1657ceb985027d1eb549e7c9a8897ab16fe86
parentb18c3e0361f58fca371eed141e7533ac4c078466 (diff)
downloadimag-1c6b02454c5617c6c0b99a9008b76917db3fc699.zip
imag-1c6b02454c5617c6c0b99a9008b76917db3fc699.tar.gz
Remove unused functions
-rw-r--r--lib/etc/libimaginteraction/src/ask.rs169
1 files changed, 0 insertions, 169 deletions
diff --git a/lib/etc/libimaginteraction/src/ask.rs b/lib/etc/libimaginteraction/src/ask.rs
index ea112d7..f36fa2e 100644
--- a/lib/etc/libimaginteraction/src/ask.rs
+++ b/lib/etc/libimaginteraction/src/ask.rs
@@ -21,17 +21,14 @@
use std::io::BufRead;
use std::io::BufReader;
-use std::result::Result as RResult;
use std::io::Read;
use std::io::Write;
use regex::Regex;
use ansi_term::Colour::*;
-use interactor::*;
use failure::Error;
use failure::ResultExt;
use failure::Fallible as Result;
-use failure::err_msg;
/// Ask the user for a Yes/No answer. Optionally provide a default value. If none is provided, this
/// keeps loop{}ing
@@ -67,111 +64,6 @@ fn ask_bool_<R: BufRead>(s: &str, default: Option<bool>, input: &mut R, output:
}
}
-/// Ask the user for an unsigned number. Optionally provide a default value. If none is provided,
-/// this keeps loop{}ing
-pub fn ask_uint(s: &str, default: Option<u64>, input: &mut Read, output: &mut Write) -> Result<u64> {
- ask_uint_(s, default, &mut BufReader::new(input), output)
-}
-
-fn ask_uint_<R: BufRead>(s: &str, default: Option<u64>, input: &mut R, output: &mut Write) -> Result<u64> {
- use std::str::FromStr;
-
- loop {
- ask_question(s, false, output)?;
-
- let mut s = String::new();
- let _ = input.read_line(&mut s);
-
- let u : RResult<u64, _> = FromStr::from_str(&s[..]);
- match u {
- Ok(u) => { return Ok(u); },
- Err(_) => {
- if default.is_some() {
- return Ok(default.unwrap());
- } // else keep looping
- }
- }
- }
-}
-
-/// Ask the user for a String.
-///
-/// If `permit_empty` is set to false, the default value will be returned if the user inserts an
-/// empty string.
-///
-/// If the `permit_empty` value is true, the `default` value is never returned.
-///
-/// If the `permit_multiline` is set to true, the `prompt` will be displayed before each input line.
-///
-/// If the `eof` parameter is `None`, the input ends as soon as there is an empty line input from
-/// the user. If the parameter is `Some(text)`, the input ends if the input line is equal to `text`.
-pub fn ask_string(s: &str,
- default: Option<String>,
- permit_empty: bool,
- permit_multiline: bool,
- eof: Option<&str>,
- prompt: &str,
- input: &mut Read,
- output: &mut Write)
- -> Result<String>
-{
- ask_string_(s,
- default,
- permit_empty,
- permit_multiline,
- eof,
- prompt,
- &mut BufReader::new(input),
- output)
-}
-
-fn ask_string_<R: BufRead>(s: &str,
- default: Option<String>,
- permit_empty: bool,
- permit_multiline: bool,
- eof: Option<&str>,
- prompt: &str,
- input: &mut R,
- output: &mut Write)
- -> Result<String>
-{
- let mut v = vec![];
- loop {
- ask_question(s, true, output)?;
- write!(output, "{}", prompt)?;
-
- let mut s = String::new();
- let _ = input.read_line(&mut s);
-
- if permit_multiline {
- if permit_multiline && eof.map_or(false, |e| e == s) {
- return Ok(v.join("\n"));
- }
-
- if permit_empty || !v.is_empty() {
- v.push(s);
- }
- write!(output, "{}", prompt)?;
- } else if s.is_empty() && permit_empty {
- return Ok(s);
- } else if s.is_empty() && !permit_empty {
- if default.is_some() {
- return Ok(default.unwrap());
- } else {
- continue;
- }
- } else {
- return Ok(s);
- }
- }
-}
-
-pub fn ask_select_from_list(list: &[&str]) -> Result<String> {
- pick_from_list(default_menu_cmd().as_mut(), list, "Selection: ")
- .context(err_msg("Unknown interaction error"))
- .map_err(Error::from)
-}
-
/// Helper function to print a imag question string. The `question` argument may not contain a
/// trailing questionmark.
///
@@ -191,7 +83,6 @@ mod test {
use std::io::BufReader;
use super::ask_bool_;
- use super::ask_uint_;
#[test]
fn test_ask_bool_nodefault_yes() {
@@ -313,64 +204,4 @@ mod test {
assert!(true == ask_bool_(question, default, &mut BufReader::new(answers.as_bytes()), &mut sink).unwrap());
}
- #[test]
- fn test_ask_uint_nodefault() {
- let question = "Is this 1";
- let default = None;
- let answers = "1";
- let mut sink: Vec<u8> = vec![];
-
- assert!(1 == ask_uint_(question, default, &mut BufReader::new(answers.as_bytes()), &mut sink).unwrap());
- }
-
- #[test]
- fn test_ask_uint_default() {
- let question = "Is this 1";
- let default = Some(1);
- let answers = "1";
- let mut sink: Vec<u8> = vec![];
-
- assert!(1 == ask_uint_(question, default, &mut BufReader::new(answers.as_bytes()), &mut sink).unwrap());
- }
-
- #[test]
- fn test_ask_uint_default_2_input_1() {
- let question = "Is this 1";
- let default = Some(2);
- let answers = "1";
- let mut sink: Vec<u8> = vec![];
-
- assert!(1 == ask_uint_(question, default, &mut BufReader::new(answers.as_bytes()), &mut sink).unwrap());
- }
-
- #[test]
- fn test_ask_uint_default_2_noinput() {
- let question = "Is this 1";
- let default = Some(2);
- let answers = "\n";
- let mut sink: Vec<u8> = vec![];
-
- assert!(2 == ask_uint_(question, default, &mut BufReader::new(answers.as_bytes()), &mut sink).unwrap());
- }
-
- #[test]
- fn test_ask_uint_default_2_several_noinput() {
- let question = "Is this 1";
- let default = Some(2);
- let answers = "\n\n\n\n";
- let mut sink: Vec<u8> = vec![];
-
- assert!(2 == ask_uint_(question, default, &mut BufReader::new(answers.as_bytes()), &mut sink).unwrap());
- }
-
- #[test]
- fn test_ask_uint_default_2_wrong_input() {
- let question = "Is this 1";
- let default = Some(2);
- let answers = "\n\n\nasfb\nsakjf\naskjf\n-2";
- let mut sink: Vec<u8> = vec![];
-
- assert!(2 == ask_uint_(question, default, &mut BufReader::new(answers.as_bytes()), &mut sink).unwrap());
- }
-
}