Skip to content

Commit 51d7665

Browse files
committed
rustdoc: remove hand-rolled isatty
1 parent 256721e commit 51d7665

File tree

3 files changed

+17
-41
lines changed

3 files changed

+17
-41
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4679,6 +4679,7 @@ version = "0.0.0"
46794679
dependencies = [
46804680
"arrayvec",
46814681
"askama",
4682+
"atty",
46824683
"expect-test",
46834684
"itertools 0.9.0",
46844685
"minifier",

src/librustdoc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ path = "lib.rs"
99
[dependencies]
1010
arrayvec = { version = "0.7", default-features = false }
1111
askama = { version = "0.11", default-features = false }
12+
atty = "0.2"
1213
pulldown-cmark = { version = "0.9", default-features = false }
1314
minifier = "0.0.41"
1415
rayon = "1.3.1"

src/librustdoc/lib.rs

+15-41
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ extern crate tikv_jemalloc_sys;
7070
use tikv_jemalloc_sys as jemalloc_sys;
7171

7272
use std::default::Default;
73-
use std::env;
73+
use std::env::{self, VarError};
74+
use std::io;
7475
use std::process;
7576

7677
use rustc_driver::{abort_on_err, describe_lints};
@@ -178,47 +179,20 @@ pub fn main() {
178179
}
179180

180181
fn init_logging() {
181-
use std::io;
182-
183-
// FIXME remove these and use winapi 0.3 instead
184-
// Duplicates: bootstrap/compile.rs, librustc_errors/emitter.rs, rustc_driver/lib.rs
185-
#[cfg(unix)]
186-
fn stdout_isatty() -> bool {
187-
extern crate libc;
188-
unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
189-
}
190-
191-
#[cfg(windows)]
192-
fn stdout_isatty() -> bool {
193-
extern crate winapi;
194-
use winapi::um::consoleapi::GetConsoleMode;
195-
use winapi::um::processenv::GetStdHandle;
196-
use winapi::um::winbase::STD_OUTPUT_HANDLE;
197-
198-
unsafe {
199-
let handle = GetStdHandle(STD_OUTPUT_HANDLE);
200-
let mut out = 0;
201-
GetConsoleMode(handle, &mut out) != 0
202-
}
203-
}
204-
205-
let color_logs = match std::env::var("RUSTDOC_LOG_COLOR") {
206-
Ok(value) => match value.as_ref() {
207-
"always" => true,
208-
"never" => false,
209-
"auto" => stdout_isatty(),
210-
_ => early_error(
211-
ErrorOutputType::default(),
212-
&format!(
213-
"invalid log color value '{}': expected one of always, never, or auto",
214-
value
215-
),
216-
),
217-
},
218-
Err(std::env::VarError::NotPresent) => stdout_isatty(),
219-
Err(std::env::VarError::NotUnicode(_value)) => early_error(
182+
let color_logs = match std::env::var("RUSTDOC_LOG_COLOR").as_deref() {
183+
Ok("always") => true,
184+
Ok("never") => false,
185+
Ok("auto") | Err(VarError::NotPresent) => atty::is(atty::Stream::Stdout),
186+
Ok(value) => early_error(
187+
ErrorOutputType::default(),
188+
&format!("invalid log color value '{}': expected one of always, never, or auto", value),
189+
),
190+
Err(VarError::NotUnicode(value)) => early_error(
220191
ErrorOutputType::default(),
221-
"non-Unicode log color value: expected one of always, never, or auto",
192+
&format!(
193+
"invalid log color value '{}': expected one of always, never, or auto",
194+
value.to_string_lossy()
195+
),
222196
),
223197
};
224198
let filter = tracing_subscriber::EnvFilter::from_env("RUSTDOC_LOG");

0 commit comments

Comments
 (0)