Skip to content

Commit 284199b

Browse files
authored
Rollup merge of #92819 - euclio:atty, r=CraftSpider
rustdoc: remove hand-rolled isatty This PR replaces bindings to the platform-specific isatty APIs with the `isatty` crate, as done elsewhere in the repository.
2 parents f0825b8 + 51d7665 commit 284199b

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
@@ -4728,6 +4728,7 @@ version = "0.0.0"
47284728
dependencies = [
47294729
"arrayvec",
47304730
"askama",
4731+
"atty",
47314732
"expect-test",
47324733
"itertools 0.9.0",
47334734
"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
@@ -71,7 +71,8 @@ extern crate tikv_jemalloc_sys;
7171
use tikv_jemalloc_sys as jemalloc_sys;
7272

7373
use std::default::Default;
74-
use std::env;
74+
use std::env::{self, VarError};
75+
use std::io;
7576
use std::process;
7677

7778
use rustc_driver::{abort_on_err, describe_lints};
@@ -179,47 +180,20 @@ pub fn main() {
179180
}
180181

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

0 commit comments

Comments
 (0)