use std::io::{self, Write};
use anyhow::Result;
pub(crate) fn print_line(text: &str) -> Result<()> {
write_line(io::stdout().lock(), text)
}
pub(crate) fn eprint_line(text: &str) -> Result<()> {
write_line(io::stderr().lock(), text)
}
fn write_line(mut writer: impl Write, text: &str) -> Result<()> {
match writeln!(writer, "{text}").and_then(|()| writer.flush()) {
Err(err) if err.kind() == io::ErrorKind::BrokenPipe => Ok(()),
result => Ok(result?),
}
}