From f9066cc4130a42be2c243f1ac912b74dbd3f6a76 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 8 Feb 2024 16:49:31 -0800 Subject: [PATCH 1/2] Port rust-lang/rust#119664 to is-terminal. Port rust-lang/rust#119664 to is-terminal. The commit message is: Fix msys2 tty detection for /dev/ptmx Our "true negative" detection assumes that if at least one std handle is a Windows console then no other handle will be a msys2 tty pipe. This turns out to be a faulty assumption in the case of `/dev/ptmx`. --- src/lib.rs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f409e48..55773fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,7 +106,7 @@ impl IsTerminal for Stream { // The Windows implementation here is copied from `handle_is_console` in // library/std/src/sys/pal/windows/io.rs in Rust at revision -// 99128b7e45f8b95d962da2e6ea584767f0c85455. +// e74c667a53c6368579867a74494e6fb7a7f17d13. #[cfg(windows)] fn handle_is_console(handle: BorrowedHandle<'_>) -> bool { @@ -128,20 +128,6 @@ fn handle_is_console(handle: BorrowedHandle<'_>) -> bool { return true; } - // At this point, we *could* have a false negative. We can determine that this is a true - // negative if we can detect the presence of a console on any of the standard I/O streams. If - // another stream has a console, then we know we're in a Windows console and can therefore - // trust the negative. - for std_handle in [STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE] { - let std_handle = GetStdHandle(std_handle); - if std_handle != 0 - && std_handle != handle as HANDLE - && GetConsoleMode(std_handle, &mut out) != 0 - { - return false; - } - } - // Otherwise, we fall back to an msys hack to see if we can detect the presence of a pty. msys_tty_on(handle as HANDLE) } From 32bbc1e073d69c57d369bd8676f3286c826cc2dd Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 8 Feb 2024 16:57:18 -0800 Subject: [PATCH 2/2] Fix unused import warnings. --- src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 55773fd..56c38cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,9 +110,7 @@ impl IsTerminal for Stream { #[cfg(windows)] fn handle_is_console(handle: BorrowedHandle<'_>) -> bool { - use windows_sys::Win32::System::Console::{ - GetConsoleMode, GetStdHandle, STD_ERROR_HANDLE, STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, - }; + use windows_sys::Win32::System::Console::GetConsoleMode; let handle = handle.as_raw_handle();