Skip to content

Commit f8835c9

Browse files
authored
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 8dafe57 commit f8835c9

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
@@ -106,13 +106,11 @@ impl<Stream: AsHandle> IsTerminal for Stream {
106106

107107
// The Windows implementation here is copied from `handle_is_console` in
108108
// library/std/src/sys/pal/windows/io.rs in Rust at revision
109-
// 99128b7e45f8b95d962da2e6ea584767f0c85455.
109+
// e74c667a53c6368579867a74494e6fb7a7f17d13.
110110

111111
#[cfg(windows)]
112112
fn handle_is_console(handle: BorrowedHandle<'_>) -> bool {
113-
use windows_sys::Win32::System::Console::{
114-
GetConsoleMode, GetStdHandle, STD_ERROR_HANDLE, STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
115-
};
113+
use windows_sys::Win32::System::Console::GetConsoleMode;
116114

117115
let handle = handle.as_raw_handle();
118116

@@ -128,20 +126,6 @@ fn handle_is_console(handle: BorrowedHandle<'_>) -> bool {
128126
return true;
129127
}
130128

131-
// At this point, we *could* have a false negative. We can determine that this is a true
132-
// negative if we can detect the presence of a console on any of the standard I/O streams. If
133-
// another stream has a console, then we know we're in a Windows console and can therefore
134-
// trust the negative.
135-
for std_handle in [STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE] {
136-
let std_handle = GetStdHandle(std_handle);
137-
if std_handle != 0
138-
&& std_handle != handle as HANDLE
139-
&& GetConsoleMode(std_handle, &mut out) != 0
140-
{
141-
return false;
142-
}
143-
}
144-
145129
// Otherwise, we fall back to an msys hack to see if we can detect the presence of a pty.
146130
msys_tty_on(handle as HANDLE)
147131
}

0 commit comments

Comments
 (0)