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 && (1..=9).contains(&n) {
11 break n;
12 }
13 println!("{} is not a valid level.", response);
14 }
15}
16
17pub fn ask(message: &str) -> bool {
19 let mut message = message.to_owned();
20 message.push_str(" [y/n] ");
21 request(&message).to_lowercase() == "y"
22}
23
24pub fn request(message: &str) -> String {
26 print!("{}", message);
27 io::stdout().flush().unwrap();
28 let mut response = String::new();
29 io::stdin().read_line(&mut response).unwrap();
30 response.trim().to_string()
31}