Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lif committed Feb 14, 2024
1 parent bbf55c9 commit 17c823d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@ impl<O: AsyncWriteExt + Unpin + Send + AsRawFdHandle> Console<O> {
)?);
Ok(Self::new_inner(stdin, stdout, escape, raw_guard))
}
}

// this is really silly.
#[cfg(any(test, not(target_family = "windows")))]
use std::marker::Sized as MightBeRawHandle;
#[cfg(all(not(test), target_family = "windows"))]
use std::os::windows::io::AsRawHandle as MightBeRawHandle;

impl<O: AsyncWriteExt + Unpin + Send + MightBeRawHandle> Console<O> {
fn new_inner<I: AsyncReadExt + Unpin + Send + 'static>(
stdin: I,
stdout: O,
Expand Down Expand Up @@ -133,7 +141,7 @@ impl<O: AsyncWriteExt + Unpin + Send + AsRawFdHandle> Console<O> {
/// Write the given bytes to stdout.
pub async fn write_stdout(&mut self, bytes: &[u8]) -> Result<(), Error> {
// windows io in rust fails if any byte sequences aren't valid utf8
#[cfg(target_family = "windows")]
#[cfg(all(not(test), target_family = "windows"))]
{
use winapi::shared::minwindef::LPDWORD;
use winapi::um::winnt::{HANDLE, VOID};
Expand All @@ -151,7 +159,7 @@ impl<O: AsyncWriteExt + Unpin + Send + AsRawFdHandle> Console<O> {
return Err(std::io::Error::last_os_error().into());
}
}
#[cfg(not(target_family = "windows"))]
#[cfg(any(test, not(target_family = "windows")))]
{
self.stdout.write_all(bytes).await?;
self.stdout.flush().await?;
Expand Down

0 comments on commit 17c823d

Please sign in to comment.