use std::io::{self, BufRead, Write};
use anyhow::Result;
pub fn prompt(message: &str) -> Result<String> {
let stdout = io::stdout();
let mut handle = stdout.lock();
write!(handle, "{message}")?;
handle.flush()?;
drop(handle);
let stdin = io::stdin();
let mut line = String::new();
stdin.lock().read_line(&mut line)?;
if line.ends_with('\n') {
line.pop();
if line.ends_with('\r') {
line.pop();
}
}
Ok(line)
}
pub fn prompt_yes_no(message: &str) -> Result<bool> {
let answer = prompt(message)?.trim().to_ascii_lowercase();
Ok(answer == "y" || answer == "yes")
}