rash/src/interface.rs

22 lines
421 B
Rust

use std::io::Write;
use std::io::{stdin, stdout};
fn print_prompt() {
print!("$ ");
stdout().flush().unwrap();
}
pub fn get_user_input() -> Option<String> {
print_prompt();
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),
}
}