//! Low-level ANSI-styling /// Write ANSI colored text to the stream pub fn write_colored( stream: &mut S, fg: Option, bg: Option, data: &[u8], ) -> std::io::Result { let non_default = fg.is_some() || bg.is_some(); if non_default { if let Some(fg) = fg { write!(stream, "{}", fg.render_fg())?; } if let Some(bg) = bg { write!(stream, "{}", bg.render_bg())?; } } let written = stream.write(data)?; if non_default { write!(stream, "{}", anstyle::Reset.render())?; } Ok(written) }