From 159caaa8f01b06e52061d971c4137e02b74645af Mon Sep 17 00:00:00 2001 From: Alex Huszagh Date: Tue, 22 Nov 2022 12:29:31 -0600 Subject: [PATCH] Replace atty with is-terminal. --- Cargo.lock | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 2 +- deny.toml | 6 ++- src/shell.rs | 25 +++++++--- 4 files changed, 155 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ad41e9c8..ba0226801 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,7 +41,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi", ] @@ -195,7 +195,6 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" name = "cross" version = "0.2.4" dependencies = [ - "atty", "clap", "color-eyre", "const-sha1", @@ -205,6 +204,7 @@ dependencies = [ "eyre", "home", "ignore", + "is-terminal", "libc", "nix", "once_cell", @@ -276,6 +276,27 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "eyre" version = "0.6.8" @@ -346,6 +367,15 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + [[package]] name = "home" version = "0.5.3" @@ -401,6 +431,28 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "io-lifetimes" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7d367024b3f3414d8e01f437f704f41a9f64ab36f9067fa73e526ad4c763c87" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "is-terminal" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae5bc6e2eb41c9def29a3e0f1306382807764b9b53112030eff57435667352d" +dependencies = [ + "hermit-abi 0.2.6", + "io-lifetimes", + "rustix", + "windows-sys", +] + [[package]] name = "is_ci" version = "1.1.1" @@ -434,6 +486,12 @@ version = "0.2.134" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" +[[package]] +name = "linux-raw-sys" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb68f22743a3fb35785f1e7f844ca5a3de2dde5bd0c0ef5b372065814699b121" + [[package]] name = "log" version = "0.4.17" @@ -628,6 +686,20 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.36.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "203974af07ea769452490ee8de3e5947971efc3a090dca8a779dd432d3fa46a7" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" version = "1.0.11" @@ -994,6 +1066,63 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + [[package]] name = "xtask" version = "0.0.0-dev.0" diff --git a/Cargo.toml b/Cargo.toml index 5f2f2e867..c253bea71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ dev = [] members = ["xtask"] [dependencies] -atty = "0.2" +is-terminal = "0.4.0" clap = { version = "4.0", features = ["derive"] } color-eyre = { version = "0.6.2", default-features = false, features = ["track-caller"] } eyre = "0.6" diff --git a/deny.toml b/deny.toml index de329b1e5..afc597fd8 100644 --- a/deny.toml +++ b/deny.toml @@ -12,7 +12,11 @@ vulnerability = "deny" unmaintained = "deny" notice = "deny" unsound = "deny" -ignore = [] +# FIXME: remove this if/when clap changes to is-terminal, atty is +# patched, or we migrated to an MSRV of 1.66.0. +ignore = [ + "RUSTSEC-2021-0145", +] [bans] multiple-versions = "deny" diff --git a/src/shell.rs b/src/shell.rs index 0ec20ae8d..9834cff5c 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -8,6 +8,7 @@ use std::str::FromStr; use crate::config::bool_from_envvar; use crate::errors::Result; +use is_terminal::IsTerminal; use owo_colors::{self, OwoColorize}; // get the prefix for stderr messages @@ -441,13 +442,11 @@ fn get_verbosity( } pub trait Stream { - const TTY: atty::Stream; + type TTY: IsTerminal; const OWO: owo_colors::Stream; #[must_use] - fn is_atty() -> bool { - atty::is(Self::TTY) - } + fn is_atty() -> bool; fn owo(&self) -> owo_colors::Stream { Self::OWO @@ -455,18 +454,30 @@ pub trait Stream { } impl Stream for io::Stdin { - const TTY: atty::Stream = atty::Stream::Stdin; + type TTY = io::Stdin; const OWO: owo_colors::Stream = owo_colors::Stream::Stdin; + + fn is_atty() -> bool { + io::stdin().is_terminal() + } } impl Stream for io::Stdout { - const TTY: atty::Stream = atty::Stream::Stdout; + type TTY = io::Stdout; const OWO: owo_colors::Stream = owo_colors::Stream::Stdout; + + fn is_atty() -> bool { + io::stdout().is_terminal() + } } impl Stream for io::Stderr { - const TTY: atty::Stream = atty::Stream::Stderr; + type TTY = io::Stderr; const OWO: owo_colors::Stream = owo_colors::Stream::Stderr; + + fn is_atty() -> bool { + io::stderr().is_terminal() + } } pub fn default_ident() -> usize {