2024-04-09 17:02:54 +02:00
|
|
|
use std::io::Write;
|
|
|
|
use std::io::{stdin, stdout};
|
|
|
|
|
2024-04-17 10:25:06 +02:00
|
|
|
fn print_prompt() {
|
2024-04-09 17:02:54 +02:00
|
|
|
print!("$ ");
|
|
|
|
stdout().flush().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_user_input() -> Option<String> {
|
2024-04-17 10:25:06 +02:00
|
|
|
print_prompt();
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
if bytes_read == 0 {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(user_input)
|
|
|
|
}
|
|
|
|
}
|