use std::io::Write;
pub fn read_reply() -> std::io::Result<String> {
let mut reply = String::new();
std::io::stdin().read_line(&mut reply)?;
if !reply.ends_with('\n') {
return Err(std::io::Error::new(
std::io::ErrorKind::UnexpectedEof,
"unexpected end of file",
));
}
reply.pop();
if reply.ends_with('\r') {
reply.pop();
}
Ok(reply)
}
pub fn prompt_reply_stdout(prompt: &str) -> std::io::Result<String> {
let mut stdout = std::io::stdout();
write!(stdout, "{}", prompt)?;
stdout.flush()?;
read_reply()
}
pub fn prompt_reply_stderr(prompt: &str) -> std::io::Result<String> {
let mut stderr = std::io::stderr();
write!(stderr, "{}", prompt)?;
stderr.flush()?;
read_reply()
}