From 1b6a04ca5504955c571d1c97504fb45ea0befee4 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 8 Jan 2024 01:21:28 +0400 Subject: Initial vendor packages Signed-off-by: Valentin Popov --- vendor/anstyle-wincon/src/ansi.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 vendor/anstyle-wincon/src/ansi.rs (limited to 'vendor/anstyle-wincon/src/ansi.rs') diff --git a/vendor/anstyle-wincon/src/ansi.rs b/vendor/anstyle-wincon/src/ansi.rs new file mode 100644 index 0000000..6ac7193 --- /dev/null +++ b/vendor/anstyle-wincon/src/ansi.rs @@ -0,0 +1,25 @@ +//! 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) +} -- cgit v1.2.3