mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
rustdoc: remove hand-rolled isatty
This commit is contained in:
parent
256721ee51
commit
51d7665be1
@ -4679,6 +4679,7 @@ version = "0.0.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"askama",
|
"askama",
|
||||||
|
"atty",
|
||||||
"expect-test",
|
"expect-test",
|
||||||
"itertools 0.9.0",
|
"itertools 0.9.0",
|
||||||
"minifier",
|
"minifier",
|
||||||
|
@ -9,6 +9,7 @@ path = "lib.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
arrayvec = { version = "0.7", default-features = false }
|
arrayvec = { version = "0.7", default-features = false }
|
||||||
askama = { version = "0.11", default-features = false }
|
askama = { version = "0.11", default-features = false }
|
||||||
|
atty = "0.2"
|
||||||
pulldown-cmark = { version = "0.9", default-features = false }
|
pulldown-cmark = { version = "0.9", default-features = false }
|
||||||
minifier = "0.0.41"
|
minifier = "0.0.41"
|
||||||
rayon = "1.3.1"
|
rayon = "1.3.1"
|
||||||
|
@ -70,7 +70,8 @@ extern crate tikv_jemalloc_sys;
|
|||||||
use tikv_jemalloc_sys as jemalloc_sys;
|
use tikv_jemalloc_sys as jemalloc_sys;
|
||||||
|
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::env;
|
use std::env::{self, VarError};
|
||||||
|
use std::io;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
use rustc_driver::{abort_on_err, describe_lints};
|
use rustc_driver::{abort_on_err, describe_lints};
|
||||||
@ -178,47 +179,20 @@ pub fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn init_logging() {
|
fn init_logging() {
|
||||||
use std::io;
|
let color_logs = match std::env::var("RUSTDOC_LOG_COLOR").as_deref() {
|
||||||
|
Ok("always") => true,
|
||||||
// FIXME remove these and use winapi 0.3 instead
|
Ok("never") => false,
|
||||||
// Duplicates: bootstrap/compile.rs, librustc_errors/emitter.rs, rustc_driver/lib.rs
|
Ok("auto") | Err(VarError::NotPresent) => atty::is(atty::Stream::Stdout),
|
||||||
#[cfg(unix)]
|
Ok(value) => early_error(
|
||||||
fn stdout_isatty() -> bool {
|
|
||||||
extern crate libc;
|
|
||||||
unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn stdout_isatty() -> bool {
|
|
||||||
extern crate winapi;
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let color_logs = match std::env::var("RUSTDOC_LOG_COLOR") {
|
|
||||||
Ok(value) => match value.as_ref() {
|
|
||||||
"always" => true,
|
|
||||||
"never" => false,
|
|
||||||
"auto" => stdout_isatty(),
|
|
||||||
_ => early_error(
|
|
||||||
ErrorOutputType::default(),
|
|
||||||
&format!(
|
|
||||||
"invalid log color value '{}': expected one of always, never, or auto",
|
|
||||||
value
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
Err(std::env::VarError::NotPresent) => stdout_isatty(),
|
|
||||||
Err(std::env::VarError::NotUnicode(_value)) => early_error(
|
|
||||||
ErrorOutputType::default(),
|
ErrorOutputType::default(),
|
||||||
"non-Unicode log color value: expected one of always, never, or auto",
|
&format!("invalid log color value '{}': expected one of always, never, or auto", value),
|
||||||
|
),
|
||||||
|
Err(VarError::NotUnicode(value)) => early_error(
|
||||||
|
ErrorOutputType::default(),
|
||||||
|
&format!(
|
||||||
|
"invalid log color value '{}': expected one of always, never, or auto",
|
||||||
|
value.to_string_lossy()
|
||||||
|
),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
let filter = tracing_subscriber::EnvFilter::from_env("RUSTDOC_LOG");
|
let filter = tracing_subscriber::EnvFilter::from_env("RUSTDOC_LOG");
|
||||||
|
Loading…
Reference in New Issue
Block a user