1use std::io;
4use std::io::prelude::*;
5
6pub fn select_level() -> usize {
7 loop {
8 let response = request("Choose level to play [1-9] ");
9 if let Ok(n) = response.parse::<usize>() {
10 if (1..=9).contains(&n) {
11 break n;
12 }
13 }
14 println!("{} is not a valid level.", response);
15 }
16}
17
18pub fn ask(message: &str) -> bool {
20 let mut message = message.to_owned();
21 message.push_str(" [y/n] ");
22 request(&message).to_lowercase() == "y"
23}
24
25pub fn request(message: &str) -> String {
27 print!("{}", message);
28 io::stdout().flush().unwrap();
29 let mut response = String::new();
30 io::stdin().read_line(&mut response).unwrap();
31 response.trim().to_string()
32}