Skip to content

Commit 6f22c08

Browse files
committed
feat: implement log isatty for windows, #5936
1 parent e31481d commit 6f22c08

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

stacks-common/src/util/log.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,25 @@ fn isatty(stream: Stream) -> bool {
345345
unsafe { libc::isatty(fd) != 0 }
346346
}
347347

348-
#[cfg(not(unix))]
348+
#[cfg(windows)]
349349
fn isatty(stream: Stream) -> bool {
350-
false
350+
use winapi::um::consoleapi::GetConsoleMode;
351+
use winapi::um::handleapi::INVALID_HANDLE_VALUE;
352+
use winapi::um::processenv::GetStdHandle;
353+
use winapi::um::winbase::{STD_OUTPUT_HANDLE, STD_ERROR_HANDLE};
354+
355+
let handle = match stream {
356+
Stream::Stdout => STD_OUTPUT_HANDLE,
357+
Stream::Stderr => STD_ERROR_HANDLE,
358+
};
359+
360+
unsafe {
361+
let handle = GetStdHandle(handle);
362+
if handle == INVALID_HANDLE_VALUE {
363+
return false;
364+
}
365+
366+
let mut mode: u32 = 0;
367+
GetConsoleMode(handle, &mut mode) != 0
368+
}
351369
}

0 commit comments

Comments
 (0)