use crate::color::{Console, Tone};
use std::fmt::Display;
use std::io::Write;
pub(crate) fn collect_to_string(write: impl FnOnce(&mut Vec<u8>) -> std::io::Result<()>) -> String {
let mut buf = Vec::new();
write(&mut buf).expect("writing to a Vec<u8> is infallible");
String::from_utf8(buf).expect("runemark writers only emit UTF-8 text")
}
pub(crate) fn write_toned_line(
prefix: &str,
console: Console,
tone: Tone,
text: impl Display,
writer: &mut (impl Write + ?Sized),
) -> std::io::Result<()> {
write!(writer, "{prefix}")?;
console.write_paint(tone, text, writer)?;
writeln!(writer)
}
pub(crate) fn write_toned_suffix(
console: Console,
tone: Tone,
text: impl Display,
writer: &mut (impl Write + ?Sized),
) -> std::io::Result<()> {
write!(writer, " ")?;
console.write_paint(tone, text, writer)
}