Skip to content

Commit

Permalink
WIP: ignore non-utf8-ness on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
lif committed Feb 14, 2024
1 parent c5231a7 commit a79a37c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,24 @@ impl<O: AsyncWriteExt + Unpin + Send> Console<O> {

/// 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(())
}

Expand Down

0 comments on commit a79a37c

Please sign in to comment.