use std::io;
use std::io::Read;
use std::io::Write;
pub fn read_line(msg: &str, prompt: &str) -> String {
self::prompt(msg, prompt);
let mut string = String::new();
io::stdin()
.read_line(&mut string)
.expect("Failed to read from stdin");
string
}
pub fn read_all(msg: &str, prompt: &str) -> String {
self::prompt(msg, prompt);
let mut string = String::new();
io::stdin()
.read_to_string(&mut string)
.expect("Failed to read from stdin");
string
}
pub fn read_num(num_bytes: usize, msg: &str, prompt: &str) -> Result<String, std::str::Utf8Error> {
self::prompt(msg, prompt);
let mut buf = Vec::with_capacity(num_bytes);
io::stdin()
.read_exact(&mut buf)
.expect("Failed to read from stdin");
match std::str::from_utf8(&buf) {
Ok(v) => Ok(v.to_string()),
Err(e) => Err(e),
}
}
fn prompt(msg: &str, prompt: &str) {
print!("{}{}", msg, prompt);
std::io::stdout().flush().expect("Failed to flush stdout");
}