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/anstream/src/buffer.rs | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 vendor/anstream/src/buffer.rs (limited to 'vendor/anstream/src/buffer.rs') diff --git a/vendor/anstream/src/buffer.rs b/vendor/anstream/src/buffer.rs new file mode 100644 index 0000000..9846bb7 --- /dev/null +++ b/vendor/anstream/src/buffer.rs @@ -0,0 +1,68 @@ +#![allow(deprecated)] + +/// In-memory [`RawStream`][crate::stream::RawStream] +#[derive(Clone, Default, Debug, PartialEq, Eq)] +#[deprecated(since = "0.6.2", note = "Use Vec")] +#[doc(hidden)] +pub struct Buffer(Vec); + +impl Buffer { + #[inline] + pub fn new() -> Self { + Default::default() + } + + #[inline] + pub fn with_capacity(capacity: usize) -> Self { + Self(Vec::with_capacity(capacity)) + } + + #[inline] + pub fn as_bytes(&self) -> &[u8] { + &self.0 + } +} + +impl AsRef<[u8]> for Buffer { + #[inline] + fn as_ref(&self) -> &[u8] { + self.as_bytes() + } +} + +impl std::io::Write for Buffer { + #[inline] + fn write(&mut self, buf: &[u8]) -> std::io::Result { + self.0.extend(buf); + Ok(buf.len()) + } + + #[inline] + fn flush(&mut self) -> std::io::Result<()> { + Ok(()) + } +} + +#[cfg(all(windows, feature = "wincon"))] +impl anstyle_wincon::WinconStream for Buffer { + fn write_colored( + &mut self, + fg: Option, + bg: Option, + data: &[u8], + ) -> std::io::Result { + self.0.write_colored(fg, bg, data) + } +} + +#[cfg(all(windows, feature = "wincon"))] +impl anstyle_wincon::WinconStream for &'_ mut Buffer { + fn write_colored( + &mut self, + fg: Option, + bg: Option, + data: &[u8], + ) -> std::io::Result { + (**self).write_colored(fg, bg, data) + } +} -- cgit v1.2.3