use std::io::{self, BufRead, IsTerminal, Write};
pub fn is_tty() -> bool {
io::stdin().is_terminal() && io::stderr().is_terminal()
}
pub fn write_prompt(title: &str, description: &str, prompt: &str) -> io::Result<()> {
let mut stderr = io::stderr();
if !title.is_empty() {
writeln!(stderr, "{}", title)?;
}
if !description.is_empty() {
writeln!(stderr, "{}", description)?;
}
if !prompt.is_empty() {
write!(stderr, "{}", prompt)?;
}
stderr.flush()
}
pub fn read_line() -> io::Result<String> {
let stdin = io::stdin();
let mut line = String::new();
stdin.lock().read_line(&mut line)?;
let mut input = line.as_str();
if let Some(stripped) = input.strip_suffix('\n') {
input = stripped;
}
if let Some(stripped) = input.strip_suffix('\r') {
input = stripped;
}
Ok(input.to_string())
}