diff options
author | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
---|---|---|
committer | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
commit | 1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch) | |
tree | 7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/anstyle-wincon/src/ansi.rs | |
parent | 5ecd8cf2cba827454317368b68571df0d13d7842 (diff) | |
download | fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip |
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/anstyle-wincon/src/ansi.rs')
-rw-r--r-- | vendor/anstyle-wincon/src/ansi.rs | 25 |
1 files changed, 25 insertions, 0 deletions
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<S: std::io::Write>( + stream: &mut S, + fg: Option<anstyle::AnsiColor>, + bg: Option<anstyle::AnsiColor>, + data: &[u8], +) -> std::io::Result<usize> { + 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) +} |