rash/src/interface.rs

24 lines
424 B
Rust
Raw Normal View History

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");
if bytes_read == 0 {
None
} else {
Some(user_input)
}
}