18 lines
398 B
Rust
18 lines
398 B
Rust
use std::io::Write;
|
|
use std::io::{stdin, stdout};
|
|
|
|
pub fn get_user_input(prompt: &str) -> Option<String> {
|
|
print!("{}", prompt);
|
|
stdout().flush().unwrap();
|
|
|
|
let mut user_input = String::new();
|
|
|
|
let bytes_read = stdin()
|
|
.read_line(&mut user_input)
|
|
.expect("error reading user input");
|
|
|
|
match bytes_read {
|
|
0 => None,
|
|
_ => Some(user_input),
|
|
}
|
|
}
|