From a79a37c92e84505ed22ad35f51b1ee20e1da527d Mon Sep 17 00:00:00 2001 From: lif <> Date: Tue, 13 Feb 2024 21:27:11 -0800 Subject: [PATCH] WIP: ignore non-utf8-ness on windows --- src/lib.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 65e9355..3394d95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -134,8 +134,24 @@ impl Console { /// Write the given bytes to stdout. pub async fn write_stdout(&mut self, bytes: &[u8]) -> Result<(), Error> { - self.stdout.write_all(bytes).await?; - self.stdout.flush().await?; + #[cfg(target_family = "windows")] + { + use winapi::shared::minwindef::LPDWORD; + use winapi::um::winnt::{HANDLE, VOID}; + let mut _lp_num_of_chars_written = 0u32; + winapi::um::consoleapi::WriteConsoleA( + self.stdout.as_raw_handle() as HANDLE, + bytes.as_ptr() as *const VOID, + bytes.len(), + (&mut _lp_num_of_chars_written).as_ptr() as LPDWORD, + std::ptr::null() as *const VOID, + ); + } + #[cfg(not(target_family = "windows"))] + { + self.stdout.write_all(bytes).await?; + self.stdout.flush().await?; + } Ok(()) }