2024-04-09 17:02:54 +02:00
|
|
|
use std::io::Write;
|
|
|
|
use std::io::{stdin, stdout};
|
|
|
|
|
2024-04-19 12:10:38 +02:00
|
|
|
pub fn get_user_input(prompt: &str) -> Option<String> {
|
|
|
|
print!("{}", prompt);
|
2024-04-09 17:02:54 +02:00
|
|
|
stdout().flush().unwrap();
|
2024-04-17 10:25:06 +02:00
|
|
|
|
2024-04-09 17:02:54 +02:00
|
|
|
let mut user_input = String::new();
|
|
|
|
|
|
|
|
let bytes_read = stdin()
|
|
|
|
.read_line(&mut user_input)
|
|
|
|
.expect("error reading user input");
|
|
|
|
|
2024-04-17 10:25:32 +02:00
|
|
|
match bytes_read {
|
|
|
|
0 => None,
|
|
|
|
_ => Some(user_input),
|
2024-04-09 17:02:54 +02:00
|
|
|
}
|
|
|
|
}
|