Rollup merge of #103117 - joshtriplett:use-is-terminal, r=eholk
Use `IsTerminal` in place of `atty` In any crate that can use nightly features, use `IsTerminal` rather than `atty`: - Use `IsTerminal` in `rustc_errors` - Use `IsTerminal` in `rustc_driver` - Use `IsTerminal` in `rustc_log` - Use `IsTerminal` in `librustdoc`
This commit is contained in:
commit
52cc0d5360
9 changed files with 14 additions and 17 deletions
|
@ -3535,7 +3535,6 @@ name = "rustc_errors"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"annotate-snippets",
|
"annotate-snippets",
|
||||||
"atty",
|
|
||||||
"rustc_ast",
|
"rustc_ast",
|
||||||
"rustc_ast_pretty",
|
"rustc_ast_pretty",
|
||||||
"rustc_data_structures",
|
"rustc_data_structures",
|
||||||
|
@ -3834,7 +3833,6 @@ dependencies = [
|
||||||
name = "rustc_log"
|
name = "rustc_log"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atty",
|
|
||||||
"rustc_span",
|
"rustc_span",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
|
@ -4389,7 +4387,6 @@ version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"askama",
|
"askama",
|
||||||
"atty",
|
|
||||||
"expect-test",
|
"expect-test",
|
||||||
"itertools",
|
"itertools",
|
||||||
"minifier",
|
"minifier",
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
//! This API is completely unstable and subject to change.
|
//! This API is completely unstable and subject to change.
|
||||||
|
|
||||||
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
||||||
|
#![feature(is_terminal)]
|
||||||
#![feature(once_cell)]
|
#![feature(once_cell)]
|
||||||
#![feature(decl_macro)]
|
#![feature(decl_macro)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
@ -27,7 +28,6 @@ use rustc_feature::find_gated_cfg;
|
||||||
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
|
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
|
||||||
use rustc_interface::{interface, Queries};
|
use rustc_interface::{interface, Queries};
|
||||||
use rustc_lint::LintStore;
|
use rustc_lint::LintStore;
|
||||||
use rustc_log::stdout_isatty;
|
|
||||||
use rustc_metadata::locator;
|
use rustc_metadata::locator;
|
||||||
use rustc_save_analysis as save;
|
use rustc_save_analysis as save;
|
||||||
use rustc_save_analysis::DumpHandler;
|
use rustc_save_analysis::DumpHandler;
|
||||||
|
@ -48,7 +48,7 @@ use std::default::Default;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, IsTerminal, Read, Write};
|
||||||
use std::panic::{self, catch_unwind};
|
use std::panic::{self, catch_unwind};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{self, Command, Stdio};
|
use std::process::{self, Command, Stdio};
|
||||||
|
@ -515,7 +515,7 @@ fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
|
||||||
}
|
}
|
||||||
text.push('\n');
|
text.push('\n');
|
||||||
}
|
}
|
||||||
if stdout_isatty() {
|
if io::stdout().is_terminal() {
|
||||||
show_content_with_pager(&text);
|
show_content_with_pager(&text);
|
||||||
} else {
|
} else {
|
||||||
print!("{}", text);
|
print!("{}", text);
|
||||||
|
|
|
@ -18,7 +18,6 @@ rustc_target = { path = "../rustc_target" }
|
||||||
rustc_hir = { path = "../rustc_hir" }
|
rustc_hir = { path = "../rustc_hir" }
|
||||||
rustc_lint_defs = { path = "../rustc_lint_defs" }
|
rustc_lint_defs = { path = "../rustc_lint_defs" }
|
||||||
unicode-width = "0.1.4"
|
unicode-width = "0.1.4"
|
||||||
atty = "0.2"
|
|
||||||
termcolor = "1.0"
|
termcolor = "1.0"
|
||||||
annotate-snippets = "0.9"
|
annotate-snippets = "0.9"
|
||||||
termize = "0.1.1"
|
termize = "0.1.1"
|
||||||
|
|
|
@ -28,8 +28,8 @@ use rustc_error_messages::FluentArgs;
|
||||||
use rustc_span::hygiene::{ExpnKind, MacroKind};
|
use rustc_span::hygiene::{ExpnKind, MacroKind};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cmp::{max, min, Reverse};
|
use std::cmp::{max, min, Reverse};
|
||||||
use std::io;
|
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
use std::io::{self, IsTerminal};
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use termcolor::{Ansi, BufferWriter, ColorChoice, ColorSpec, StandardStream};
|
use termcolor::{Ansi, BufferWriter, ColorChoice, ColorSpec, StandardStream};
|
||||||
|
@ -619,14 +619,14 @@ impl ColorConfig {
|
||||||
fn to_color_choice(self) -> ColorChoice {
|
fn to_color_choice(self) -> ColorChoice {
|
||||||
match self {
|
match self {
|
||||||
ColorConfig::Always => {
|
ColorConfig::Always => {
|
||||||
if atty::is(atty::Stream::Stderr) {
|
if io::stderr().is_terminal() {
|
||||||
ColorChoice::Always
|
ColorChoice::Always
|
||||||
} else {
|
} else {
|
||||||
ColorChoice::AlwaysAnsi
|
ColorChoice::AlwaysAnsi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ColorConfig::Never => ColorChoice::Never,
|
ColorConfig::Never => ColorChoice::Never,
|
||||||
ColorConfig::Auto if atty::is(atty::Stream::Stderr) => ColorChoice::Auto,
|
ColorConfig::Auto if io::stderr().is_terminal() => ColorChoice::Auto,
|
||||||
ColorConfig::Auto => ColorChoice::Never,
|
ColorConfig::Auto => ColorChoice::Never,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
||||||
#![feature(drain_filter)]
|
#![feature(drain_filter)]
|
||||||
#![feature(if_let_guard)]
|
#![feature(if_let_guard)]
|
||||||
|
#![feature(is_terminal)]
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
|
|
|
@ -4,7 +4,6 @@ version = "0.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
atty = "0.2"
|
|
||||||
tracing = "0.1.28"
|
tracing = "0.1.28"
|
||||||
tracing-subscriber = { version = "0.3.3", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
|
tracing-subscriber = { version = "0.3.3", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
|
||||||
tracing-tree = "0.2.0"
|
tracing-tree = "0.2.0"
|
||||||
|
|
|
@ -40,10 +40,11 @@
|
||||||
|
|
||||||
#![deny(rustc::untranslatable_diagnostic)]
|
#![deny(rustc::untranslatable_diagnostic)]
|
||||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||||
|
#![feature(is_terminal)]
|
||||||
|
|
||||||
use std::env::{self, VarError};
|
use std::env::{self, VarError};
|
||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
use std::io;
|
use std::io::{self, IsTerminal};
|
||||||
use tracing_subscriber::filter::{Directive, EnvFilter, LevelFilter};
|
use tracing_subscriber::filter::{Directive, EnvFilter, LevelFilter};
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
|
|
||||||
|
@ -93,11 +94,11 @@ pub fn init_env_logger(env: &str) -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stdout_isatty() -> bool {
|
pub fn stdout_isatty() -> bool {
|
||||||
atty::is(atty::Stream::Stdout)
|
io::stdout().is_terminal()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stderr_isatty() -> bool {
|
pub fn stderr_isatty() -> bool {
|
||||||
atty::is(atty::Stream::Stderr)
|
io::stderr().is_terminal()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -9,7 +9,6 @@ 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, features = ["config"] }
|
askama = { version = "0.11", default-features = false, features = ["config"] }
|
||||||
atty = "0.2"
|
|
||||||
itertools = "0.10.1"
|
itertools = "0.10.1"
|
||||||
minifier = "0.2.2"
|
minifier = "0.2.2"
|
||||||
once_cell = "1.10.0"
|
once_cell = "1.10.0"
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#![feature(box_patterns)]
|
#![feature(box_patterns)]
|
||||||
#![feature(control_flow_enum)]
|
#![feature(control_flow_enum)]
|
||||||
#![feature(drain_filter)]
|
#![feature(drain_filter)]
|
||||||
|
#![feature(is_terminal)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
|
@ -69,7 +70,7 @@ extern crate jemalloc_sys;
|
||||||
|
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::env::{self, VarError};
|
use std::env::{self, VarError};
|
||||||
use std::io;
|
use std::io::{self, IsTerminal};
|
||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
use rustc_driver::abort_on_err;
|
use rustc_driver::abort_on_err;
|
||||||
|
@ -179,7 +180,7 @@ fn init_logging() {
|
||||||
let color_logs = match std::env::var("RUSTDOC_LOG_COLOR").as_deref() {
|
let color_logs = match std::env::var("RUSTDOC_LOG_COLOR").as_deref() {
|
||||||
Ok("always") => true,
|
Ok("always") => true,
|
||||||
Ok("never") => false,
|
Ok("never") => false,
|
||||||
Ok("auto") | Err(VarError::NotPresent) => atty::is(atty::Stream::Stdout),
|
Ok("auto") | Err(VarError::NotPresent) => io::stdout().is_terminal(),
|
||||||
Ok(value) => early_error(
|
Ok(value) => early_error(
|
||||||
ErrorOutputType::default(),
|
ErrorOutputType::default(),
|
||||||
&format!("invalid log color value '{}': expected one of always, never, or auto", value),
|
&format!("invalid log color value '{}': expected one of always, never, or auto", value),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue