1
Fork 0

driver: Use atty instead of rolling our own

Rationale:

- `atty` is widely used in the Rust ecosystem
- We already use it (in `rustc_errors` and other places)
- We shouldn't be rolling our own TTY detector when there's a
  widely-used, well-tested package that we can use
This commit is contained in:
Camelid 2021-01-10 18:07:05 -08:00
parent 0406441664
commit 8c43160744
3 changed files with 4 additions and 33 deletions

View file

@ -546,43 +546,12 @@ impl Compilation {
#[derive(Copy, Clone)]
pub struct RustcDefaultCalls;
// FIXME remove these and use winapi 0.3 instead
// Duplicates: bootstrap/compile.rs, librustc_errors/emitter.rs
#[cfg(unix)]
fn stdout_isatty() -> bool {
unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
atty::is(atty::Stream::Stdout)
}
#[cfg(windows)]
fn stdout_isatty() -> bool {
use winapi::um::consoleapi::GetConsoleMode;
use winapi::um::processenv::GetStdHandle;
use winapi::um::winbase::STD_OUTPUT_HANDLE;
unsafe {
let handle = GetStdHandle(STD_OUTPUT_HANDLE);
let mut out = 0;
GetConsoleMode(handle, &mut out) != 0
}
}
// FIXME remove these and use winapi 0.3 instead
#[cfg(unix)]
fn stderr_isatty() -> bool {
unsafe { libc::isatty(libc::STDERR_FILENO) != 0 }
}
#[cfg(windows)]
fn stderr_isatty() -> bool {
use winapi::um::consoleapi::GetConsoleMode;
use winapi::um::processenv::GetStdHandle;
use winapi::um::winbase::STD_ERROR_HANDLE;
unsafe {
let handle = GetStdHandle(STD_ERROR_HANDLE);
let mut out = 0;
GetConsoleMode(handle, &mut out) != 0
}
atty::is(atty::Stream::Stderr)
}
fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {