From bb3d480e422dc76dff8383695e7c8b9e62c417ed Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 23 Nov 2022 08:14:13 -0800 Subject: [PATCH] cli: use `is_tty()` from `crossterm` crate instead of `atty` The `atty` crate seems unmaintained. There's https://rustsec.org/advisories/RUSTSEC-2021-0145 filed against it, which `cargo-deny` complains about. A fix for that has been open for well over a year without being fixed (https://github.com/softprops/atty/pull/51). It turns out the functionality is also available via the `crossterm` crate (thanks, @yuja), which we already depend on. Since we also depend on `atty` via `clap`, I also added an exception to the `cargo-deny` config. --- Cargo.lock | 1 - Cargo.toml | 1 - deny.toml | 1 + src/ui.rs | 10 +++++----- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0ed288c905..e1559fa274 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -716,7 +716,6 @@ name = "jujutsu" version = "0.5.1" dependencies = [ "assert_cmd", - "atty", "chrono", "clap 4.0.26", "clap_complete", diff --git a/Cargo.toml b/Cargo.toml index 5a3de5cc00..9eb5c26538 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,6 @@ harness = false members = ["lib"] [dependencies] -atty = "0.2.14" chrono = { version = "0.4.23", default-features = false, features = ["std", "clock"] } clap = { version = "4.0.26", features = ["derive", "deprecated"] } clap_complete = "4.0.5" diff --git a/deny.toml b/deny.toml index a1b1c102f7..92ff0c59a9 100644 --- a/deny.toml +++ b/deny.toml @@ -51,6 +51,7 @@ notice = "warn" # output a note when they are encountered. ignore = [ #"RUSTSEC-0000-0000", + "RUSTSEC-2021-0145", ] # Threshold for security vulnerabilities, any vulnerability with a CVSS score # lower than the range specified will be ignored. Note that ignored advisories diff --git a/src/ui.rs b/src/ui.rs index 3eeb53d9e8..02dd21dafe 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -17,7 +17,7 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use std::{fmt, io}; -use atty::Stream; +use crossterm::tty::IsTty; use jujutsu_lib::settings::UserSettings; use crate::formatter::{Formatter, FormatterFactory}; @@ -80,7 +80,7 @@ fn use_color(choice: ColorChoice) -> bool { match choice { ColorChoice::Always => true, ColorChoice::Never => false, - ColorChoice::Auto => atty::is(Stream::Stdout), + ColorChoice::Auto => io::stdout().is_tty(), } } @@ -154,7 +154,7 @@ impl Ui { /// Whether continuous feedback should be displayed for long-running /// operations pub fn use_progress_indicator(&self) -> bool { - self.settings().use_progress_indicator() && atty::is(Stream::Stdout) + self.settings().use_progress_indicator() && io::stdout().is_tty() } pub fn write(&mut self, text: &str) -> io::Result<()> { @@ -208,7 +208,7 @@ impl Ui { } pub fn prompt(&mut self, prompt: &str) -> io::Result { - if !atty::is(Stream::Stdout) { + if !io::stdout().is_tty() { return Err(io::Error::new( io::ErrorKind::Unsupported, "Cannot prompt for input since the output is not connected to a terminal", @@ -222,7 +222,7 @@ impl Ui { } pub fn prompt_password(&mut self, prompt: &str) -> io::Result { - if !atty::is(Stream::Stdout) { + if !io::stdout().is_tty() { return Err(io::Error::new( io::ErrorKind::Unsupported, "Cannot prompt for input since the output is not connected to a terminal",