softprops / atty

are you or are you not a tty?
MIT License
277 stars 50 forks source link

Pipes detected as a tty on MSYS #23

Closed alexcrichton closed 6 years ago

alexcrichton commented 6 years ago

I've initially attempted to integrate atty/termcolor into rustc at https://github.com/rust-lang/rust/pull/48588 but unfortunately it looks like there may be a misdiagnosis of terminal colors! It looks like in the MSYS terminal/shell pipes are classified as ttys, for example this program:

extern crate atty;
fn main() {
    println!("stdin:  {}", atty::is(atty::Stream::Stdin));
    println!("stdout: {}", atty::is(atty::Stream::Stdout));
    println!("stderr: {}", atty::is(atty::Stream::Stderr));
}

Will print:

$ echo a | cargo run 2>&1 | cat
stdin:  true
stdout: true
stderr: true

when run in MSYS.

The same program for Unix, however, prints:

$ echo a | cargo run 2>&1 | cat
stdin:  false
stdout: false
stderr: false

With some debugging it looks like the filename reported for the MSYS pipes are along the lines of:

"\\msys-dd50a72ab4668b33-2996-pipe-0x5A"
"\\msys-dd50a72ab4668b33-2996-pipe-0x5C"

which looks to trigger this logic. Was the || there supposed to be &&?