Migrate from atty to is-terminal (#4382)

This commit is contained in:
Guilherme A. de Souza 2023-02-21 17:52:18 -03:00 committed by GitHub
parent 4e7ae2d46a
commit 7d7b9eb49a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 161 additions and 70 deletions

162
Cargo.lock generated
View file

@ -67,7 +67,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",
]
@ -293,7 +293,7 @@ dependencies = [
"lazy_static",
"libc",
"unicode-width",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@ -321,7 +321,6 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
name = "coreutils"
version = "0.0.17"
dependencies = [
"atty",
"chrono",
"clap",
"clap_complete",
@ -329,6 +328,7 @@ dependencies = [
"filetime",
"glob",
"hex-literal",
"is-terminal",
"libc",
"nix",
"once_cell",
@ -635,7 +635,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1631ca6e3c59112501a9d87fd86f21591ff77acd31331e8a73f8d80a65bbdd71"
dependencies = [
"nix",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@ -834,7 +834,7 @@ dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@ -1045,6 +1045,12 @@ dependencies = [
"libc",
]
[[package]]
name = "hermit-abi"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
[[package]]
name = "hex"
version = "0.4.3"
@ -1139,6 +1145,28 @@ version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074"
[[package]]
name = "io-lifetimes"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3"
dependencies = [
"libc",
"windows-sys 0.45.0",
]
[[package]]
name = "is-terminal"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef"
dependencies = [
"hermit-abi 0.3.1",
"io-lifetimes 1.0.5",
"rustix 0.36.8",
"windows-sys 0.45.0",
]
[[package]]
name = "itertools"
version = "0.10.5"
@ -1235,6 +1263,12 @@ version = "0.0.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d"
[[package]]
name = "linux-raw-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
[[package]]
name = "lock_api"
version = "0.4.9"
@ -1326,7 +1360,7 @@ dependencies = [
"libc",
"log",
"wasi",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@ -1415,7 +1449,7 @@ version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5"
dependencies = [
"hermit-abi",
"hermit-abi 0.1.19",
"libc",
]
@ -1545,7 +1579,7 @@ dependencies = [
"libc",
"redox_syscall",
"smallvec",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@ -1693,7 +1727,7 @@ dependencies = [
"byteorder",
"hex",
"lazy_static",
"rustix",
"rustix 0.35.13",
]
[[package]]
@ -1899,10 +1933,24 @@ checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"io-lifetimes 0.7.5",
"libc",
"linux-raw-sys",
"windows-sys",
"linux-raw-sys 0.0.46",
"windows-sys 0.42.0",
]
[[package]]
name = "rustix"
version = "0.36.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644"
dependencies = [
"bitflags",
"errno",
"io-lifetimes 1.0.5",
"libc",
"linux-raw-sys 0.1.4",
"windows-sys 0.45.0",
]
[[package]]
@ -2161,8 +2209,8 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40ca90c434fd12083d1a6bdcbe9f92a14f96c8a1ba600ba451734ac334521f7a"
dependencies = [
"rustix",
"windows-sys",
"rustix 0.35.13",
"windows-sys 0.42.0",
]
[[package]]
@ -2334,8 +2382,8 @@ dependencies = [
name = "uu_cat"
version = "0.0.17"
dependencies = [
"atty",
"clap",
"is-terminal",
"nix",
"thiserror",
"uucore",
@ -2432,9 +2480,9 @@ dependencies = [
name = "uu_cut"
version = "0.0.17"
dependencies = [
"atty",
"bstr",
"clap",
"is-terminal",
"memchr",
"uucore",
]
@ -2447,7 +2495,7 @@ dependencies = [
"clap",
"libc",
"uucore",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@ -2503,7 +2551,7 @@ dependencies = [
"clap",
"glob",
"uucore",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@ -2634,7 +2682,7 @@ dependencies = [
"clap",
"hostname",
"uucore",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@ -2705,10 +2753,10 @@ dependencies = [
name = "uu_ls"
version = "0.0.17"
dependencies = [
"atty",
"chrono",
"clap",
"glob",
"is-terminal",
"lscolors",
"number_prefix",
"once_cell",
@ -2759,9 +2807,9 @@ dependencies = [
name = "uu_more"
version = "0.0.17"
dependencies = [
"atty",
"clap",
"crossterm",
"is-terminal",
"nix",
"unicode-segmentation",
"unicode-width",
@ -2801,8 +2849,8 @@ dependencies = [
name = "uu_nohup"
version = "0.0.17"
dependencies = [
"atty",
"clap",
"is-terminal",
"libc",
"uucore",
]
@ -2936,7 +2984,7 @@ dependencies = [
"libc",
"uucore",
"walkdir",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@ -3079,7 +3127,7 @@ dependencies = [
"libc",
"nix",
"uucore",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@ -3097,16 +3145,16 @@ dependencies = [
name = "uu_tail"
version = "0.0.17"
dependencies = [
"atty",
"clap",
"fundu",
"is-terminal",
"libc",
"memchr",
"notify",
"same-file",
"uucore",
"winapi-util",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@ -3146,7 +3194,7 @@ dependencies = [
"filetime",
"time",
"uucore",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@ -3186,8 +3234,8 @@ dependencies = [
name = "uu_tty"
version = "0.0.17"
dependencies = [
"atty",
"clap",
"is-terminal",
"nix",
"uucore",
]
@ -3282,7 +3330,7 @@ dependencies = [
"clap",
"libc",
"uucore",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@ -3316,7 +3364,7 @@ dependencies = [
"walkdir",
"wild",
"winapi-util",
"windows-sys",
"windows-sys 0.42.0",
"z85",
]
@ -3478,46 +3526,70 @@ dependencies = [
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.0"
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
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.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.0"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
[[package]]
name = "windows_i686_gnu"
version = "0.42.0"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
[[package]]
name = "windows_i686_msvc"
version = "0.42.0"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.0"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.0"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.0"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
[[package]]
name = "xattr"

View file

@ -263,7 +263,6 @@ feat_os_windows_legacy = [
test = [ "uu_test" ]
[workspace.dependencies]
atty = "0.2"
bigdecimal = "0.3"
binary-heap-plus = "0.5.0"
bstr = "1.0"
@ -287,6 +286,7 @@ gcd = "2.2"
glob = "0.3.0"
half = "2.1"
indicatif = "0.17"
is-terminal = "0.4.3"
itertools = "0.10.0"
libc = "0.2.139"
lscolors = { version = "0.13.0", default-features=false, features = ["nu-ansi-term"] }
@ -476,7 +476,7 @@ time = { workspace=true, features=["local-offset"] }
unindent = "0.1"
uucore = { workspace=true, features=["entries", "process", "signals"] }
walkdir = { workspace=true }
atty = { workspace=true }
is-terminal = { workspace=true }
hex-literal = "0.3.1"
rstest = "0.16.0"

View file

@ -58,12 +58,24 @@ highlight = "all"
# For each duplicate dependency, indicate the name of the dependency which
# introduces it.
# spell-checker: disable
skip = []
skip = [
# is-terminal
{ name = "hermit-abi", version = "0.3.1" },
# is-terminal
{ name = "rustix", version = "0.36.8" },
# is-terminal (via rustix)
{ name = "io-lifetimes", version = "1.0.5" },
# is-terminal
{ name = "linux-raw-sys", version = "0.1.4" },
# is-terminal
{ name = "windows-sys", version = "0.45.0" },
]
# spell-checker: enable
# This section is considered when running `cargo deny check sources`.
# More documentation about the 'sources' section can be found here:
# https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html
[sources]
unknown-registry = "warn"
unknown-git = "warn"

View file

@ -17,7 +17,7 @@ path = "src/cat.rs"
[dependencies]
clap = { workspace=true }
thiserror = { workspace = true }
atty = { workspace=true }
is-terminal = { workspace = true }
uucore = { workspace=true, features=["fs", "pipes"] }
[target.'cfg(unix)'.dependencies]

View file

@ -12,6 +12,7 @@
// last synced with: cat (GNU coreutils) 8.13
use clap::{crate_version, Arg, ArgAction, Command};
use is_terminal::IsTerminal;
use std::fs::{metadata, File};
use std::io::{self, Read, Write};
use thiserror::Error;
@ -332,7 +333,7 @@ fn cat_path(
let stdin = io::stdin();
let mut handle = InputHandle {
reader: stdin,
is_interactive: atty::is(atty::Stream::Stdin),
is_interactive: std::io::stdin().is_terminal(),
};
cat_handle(&mut handle, options, state)
}

View file

@ -19,7 +19,7 @@ clap = { workspace=true }
uucore = { workspace=true }
memchr = { workspace=true }
bstr = { workspace=true }
atty = { workspace=true }
is-terminal = { workspace=true }
[[bin]]
name = "cut"

View file

@ -9,6 +9,7 @@
use bstr::io::BufReadExt;
use clap::{crate_version, Arg, ArgAction, Command};
use is_terminal::IsTerminal;
use std::fs::File;
use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write};
use std::path::Path;
@ -136,7 +137,7 @@ enum Mode {
}
fn stdout_writer() -> Box<dyn Write> {
if atty::is(atty::Stream::Stdout) {
if std::io::stdout().is_terminal() {
Box::new(stdout())
} else {
Box::new(BufWriter::new(stdout())) as Box<dyn Write>

View file

@ -25,7 +25,7 @@ glob = { workspace=true }
lscolors = { workspace=true }
uucore = { workspace=true, features = ["entries", "fs"] }
once_cell = { workspace=true }
atty = { workspace=true }
is-terminal = { workspace=true }
selinux = { workspace=true, optional = true }
[[bin]]

View file

@ -12,6 +12,7 @@ use clap::{
crate_version, Arg, ArgAction, Command,
};
use glob::{MatchOptions, Pattern};
use is_terminal::IsTerminal;
use lscolors::LsColors;
use number_prefix::NumberPrefix;
use once_cell::unsync::OnceCell;
@ -451,7 +452,7 @@ impl Config {
(Format::Commas, Some(options::format::COMMAS))
} else if options.get_flag(options::format::COLUMNS) {
(Format::Columns, Some(options::format::COLUMNS))
} else if atty::is(atty::Stream::Stdout) {
} else if std::io::stdout().is_terminal() {
(Format::Columns, None)
} else {
(Format::OneLine, None)
@ -557,7 +558,7 @@ impl Config {
None => options.contains_id(options::COLOR),
Some(val) => match val.as_str() {
"" | "always" | "yes" | "force" => true,
"auto" | "tty" | "if-tty" => atty::is(atty::Stream::Stdout),
"auto" | "tty" | "if-tty" => std::io::stdout().is_terminal(),
/* "never" | "no" | "none" | */ _ => false,
},
};
@ -678,7 +679,7 @@ impl Config {
} else if options.get_flag(options::SHOW_CONTROL_CHARS) {
true
} else {
!atty::is(atty::Stream::Stdout)
!std::io::stdout().is_terminal()
};
let opt_quoting_style = options
@ -750,7 +751,7 @@ impl Config {
"never" | "no" | "none" => IndicatorStyle::None,
"always" | "yes" | "force" => IndicatorStyle::Classify,
"auto" | "tty" | "if-tty" => {
if atty::is(atty::Stream::Stdout) {
if std::io::stdout().is_terminal() {
IndicatorStyle::Classify
} else {
IndicatorStyle::None

View file

@ -18,7 +18,7 @@ path = "src/more.rs"
clap = { workspace=true }
uucore = { workspace=true }
crossterm = { workspace=true }
atty = { workspace=true }
is-terminal = { workspace=true }
unicode-width = { workspace=true }
unicode-segmentation = { workspace=true }

View file

@ -23,6 +23,7 @@ use crossterm::{
terminal,
};
use is_terminal::IsTerminal;
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use uucore::display::Quotable;
@ -83,7 +84,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
buff.clear();
}
reset_term(&mut stdout);
} else if atty::isnt(atty::Stream::Stdin) {
} else if !std::io::stdin().is_terminal() {
stdin().read_to_string(&mut buff).unwrap();
let mut stdout = setup_term();
more(&buff, &mut stdout, None, silent)?;

View file

@ -17,7 +17,7 @@ path = "src/nohup.rs"
[dependencies]
clap = { workspace=true }
libc = { workspace=true }
atty = { workspace=true }
is-terminal = { workspace=true }
uucore = { workspace=true, features=["fs"] }
[[bin]]

View file

@ -8,6 +8,7 @@
// spell-checker:ignore (ToDO) execvp SIGHUP cproc vprocmgr cstrs homeout
use clap::{crate_version, Arg, ArgAction, Command};
use is_terminal::IsTerminal;
use libc::{c_char, dup2, execvp, signal};
use libc::{SIGHUP, SIG_IGN};
use std::env;
@ -129,7 +130,7 @@ pub fn uu_app() -> Command {
}
fn replace_fds() -> UResult<()> {
if atty::is(atty::Stream::Stdin) {
if std::io::stdin().is_terminal() {
let new_stdin = File::open(Path::new("/dev/null"))
.map_err(|e| NohupError::CannotReplace("STDIN", e))?;
if unsafe { dup2(new_stdin.as_raw_fd(), 0) } != 0 {
@ -137,7 +138,7 @@ fn replace_fds() -> UResult<()> {
}
}
if atty::is(atty::Stream::Stdout) {
if std::io::stdout().is_terminal() {
let new_stdout = find_stdout()?;
let fd = new_stdout.as_raw_fd();
@ -146,7 +147,7 @@ fn replace_fds() -> UResult<()> {
}
}
if atty::is(atty::Stream::Stderr) && unsafe { dup2(1, 2) } != 2 {
if std::io::stderr().is_terminal() && unsafe { dup2(1, 2) } != 2 {
return Err(NohupError::CannotReplace("STDERR", Error::last_os_error()).into());
}
Ok(())

View file

@ -22,7 +22,7 @@ memchr = { workspace=true }
notify = { workspace=true }
uucore = { workspace=true }
same-file = { workspace=true }
atty = { workspace=true }
is-terminal = { workspace=true }
fundu = { workspace=true }
[target.'cfg(windows)'.dependencies]

View file

@ -7,10 +7,10 @@
use crate::paths::Input;
use crate::{parse, platform, Quotable};
use atty::Stream;
use clap::crate_version;
use clap::{parser::ValueSource, Arg, ArgAction, ArgMatches, Command};
use fundu::DurationParser;
use is_terminal::IsTerminal;
use same_file::Handle;
use std::collections::VecDeque;
use std::ffi::OsString;
@ -274,7 +274,7 @@ impl Settings {
.map_or(false, |meta| !meta.is_file())
});
if !blocking_stdin && atty::is(Stream::Stdin) {
if !blocking_stdin && std::io::stdin().is_terminal() {
show_warning!("following standard input indefinitely is ineffective");
}
}

View file

@ -17,7 +17,7 @@ path = "src/tty.rs"
[dependencies]
clap = { workspace=true }
nix = { workspace=true, features=["term"] }
atty = { workspace=true }
is-terminal = { workspace=true }
uucore = { workspace=true, features=["fs"] }
[[bin]]

View file

@ -10,6 +10,7 @@
// spell-checker:ignore (ToDO) ttyname filedesc
use clap::{crate_version, Arg, ArgAction, Command};
use is_terminal::IsTerminal;
use std::io::Write;
use std::os::unix::io::AsRawFd;
use uucore::error::{set_exit_code, UResult};
@ -30,7 +31,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// If silent, we don't need the name, only whether or not stdin is a tty.
if silent {
return if atty::is(atty::Stream::Stdin) {
return if std::io::stdin().is_terminal() {
Ok(())
} else {
Err(1.into())

View file

@ -1,9 +1,10 @@
use crate::common::util::*;
use is_terminal::IsTerminal;
#[test]
fn test_more_no_arg() {
// Reading from stdin is now supported, so this must succeed
if atty::is(atty::Stream::Stdout) {
if std::io::stdout().is_terminal() {
new_ucmd!().succeeds();
} else {
}
@ -14,7 +15,7 @@ fn test_more_dir_arg() {
// Run the test only if there's a valid terminal, else do nothing
// Maybe we could capture the error, i.e. "Device not found" in that case
// but I am leaving this for later
if atty::is(atty::Stream::Stdout) {
if std::io::stdout().is_terminal() {
new_ucmd!()
.arg(".")
.fails()