Skip to content

Commit 6f99872

Browse files
committed
Port rust-lang/rust#119664 to is-terminal. (#34)
* 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`. * Fix unused import warnings.
1 parent b40a014 commit 6f99872

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

src/lib.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,11 @@ impl<Stream: AsHandle> IsTerminal for Stream {
9696

9797
// The Windows implementation here is copied from `handle_is_console` in
9898
// library/std/src/sys/pal/windows/io.rs in Rust at revision
99-
// 99128b7e45f8b95d962da2e6ea584767f0c85455.
99+
// e74c667a53c6368579867a74494e6fb7a7f17d13.
100100

101101
#[cfg(windows)]
102102
fn handle_is_console(handle: BorrowedHandle<'_>) -> bool {
103-
use windows_sys::Win32::System::Console::{
104-
GetConsoleMode, GetStdHandle, STD_ERROR_HANDLE, STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
105-
};
103+
use windows_sys::Win32::System::Console::GetConsoleMode;
106104

107105
let handle = handle.as_raw_handle();
108106

@@ -118,20 +116,6 @@ fn handle_is_console(handle: BorrowedHandle<'_>) -> bool {
118116
return true;
119117
}
120118

121-
// At this point, we *could* have a false negative. We can determine that this is a true
122-
// negative if we can detect the presence of a console on any of the standard I/O streams. If
123-
// another stream has a console, then we know we're in a Windows console and can therefore
124-
// trust the negative.
125-
for std_handle in [STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE] {
126-
let std_handle = GetStdHandle(std_handle);
127-
if std_handle != 0
128-
&& std_handle != handle as HANDLE
129-
&& GetConsoleMode(std_handle, &mut out) != 0
130-
{
131-
return false;
132-
}
133-
}
134-
135119
// Otherwise, we fall back to an msys hack to see if we can detect the presence of a pty.
136120
msys_tty_on(handle as HANDLE)
137121
}

0 commit comments

Comments
 (0)