pub fn list<T: Clone + ToString>(
    init_msg: &str,
    type_: &str,
    items: &[(String, T)],
    show_item: bool,
) -> (String, T) {
    print_color(init_msg, Color::Magenta);
    for (i, (name, content)) in items.iter().enumerate() {
        if show_item {
            println!("{}: {}: {}", i + 1, name, content.to_string())
        } else {
            println!("{}: {}", i + 1, name)
        }
    }

    let mut mapping = HashMap::new();
    for (i, item) in items.iter().enumerate() {
        mapping.insert(i + 1, item);
    }

    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Problem reading input");

    let input = input
        .chars()
        .next()
        .expect("Problem parsing input")
        .to_string()
        .parse::<usize>();

    let input = if let Ok(ip) = input {
        ip
    } else {
        abort("Please try again; enter a number like 1 or 2 .")
    };

    let (name, content) = if let Some(r) = mapping.get(&input) {
        r
    } else {
        abort(&format!(
            "Can't find the {} associated with that number. Is it in the list above?",
            type_
        ))
    };

    (name.to_string(), content.clone())
}
/// A generic prompt function, where the user selects from a list
A generic prompt function, where the user selects from a list
A generic prompt function where the user selects from a list
pub fn list<T: Clone + ToString>(
    init_msg: &str,
    type_: &str,
    items: &[(String, T)],
    show_item: bool,
) -> (String, T) {
    print_color(init_msg, Color::Magenta);
    for (i, (name, content)) in items.iter().enumerate() {
        if show_item {
            println!("{}: {}: {}", i + 1, name, content.to_string())
        } else {
            println!("{}: {}", i + 1, name)
        }
    }
    let mut mapping = HashMap::new();
    for (i, item) in items.iter().enumerate() {
        mapping.insert(i + 1, item);
    }
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Problem reading input");
    let input = input
        .chars()
        .next()
        .expect("Problem parsing input")
        .to_string()
        .parse::<usize>();
    let input = if let Ok(ip) = input {
        ip
    } else {
        abort("Please try again; enter a number like 1 or 2 .")
    };
    let (name, content) = if let Some(r) = mapping.get(&input) {
        r
    } else {
        abort(&format!(
            "Can't find the {} associated with that number. Is it in the list above?",
            type_
        ))
    };
    (name.to_string(), content.clone())
}
pub fn list < T : Clone + ToString > ( init_msg : & str , type_ : & str , items : & [ ( String , T ) ] , show_item : bool , ) -> ( String , T ) { print_color ( init_msg , Color :: Magenta ) ; for ( i , ( name , content ) ) in items . iter ( ) . enumerate ( ) { if show_item { println ! ( " " i 1 name content to_string ( ) ) } else { println ! ( " " i 1 name ) } } let mut mapping = HashMap :: new ( ) ; for ( i , item ) in items . iter ( ) . enumerate ( ) { mapping . insert ( i + 1 , item ) ; } let mut input = String :: new ( ) ; io :: stdin ( ) . read_line ( & mut input ) . expect ( " " ) ; let input = input . chars ( ) . next ( ) . expect ( " " ) . to_string ( ) . parse :: < usize > ( ) ; let input = if let Ok ( ip ) = input { ip } else { abort ( " " ) } ; let ( name , content ) = if let Some ( r ) = mapping . get ( & input ) { r } else { abort ( & format ! ( " " type_ ) ) } ; ( name . to_string ( ) , content . clone ( ) ) }
A generic prompt function, where the user selects from a list
A generic prompt function where the user selects from a list
init_msg
&str
type_
&str
items
&[(String, T)]
show_item
bool
init_msg
&str
type_
&str
items
&[(String, T)]
show_item
bool