From 8b43363c97131ae4fc3ec4b8b232f08fe5d53109 Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Fri, 27 Oct 2023 13:15:33 -0700 Subject: [PATCH] chore(deps): Replace atty with is-terminal (#18966) `atty` seems to be unmaintained and vulnerable to https://github.com/advisories/GHSA-g98v-hv3f-hcfr. I followed `clap`'s lead and replaced with `is-termianl` (https://github.com/clap-rs/clap/pull/4249). Signed-off-by: Jesse Szwedko --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/cli.rs | 3 ++- src/test_util/mod.rs | 5 ++++- vdev/Cargo.toml | 2 +- vdev/src/util.rs | 3 ++- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f45ac0c3abb1f..1674dcc7d31ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9646,7 +9646,6 @@ name = "vdev" version = "0.1.0" dependencies = [ "anyhow", - "atty", "cached", "chrono", "clap 4.4.7", @@ -9659,6 +9658,7 @@ dependencies = [ "hex", "indexmap 2.0.2", "indicatif", + "is-terminal", "itertools 0.11.0", "log", "once_cell", @@ -9696,7 +9696,6 @@ dependencies = [ "async-nats", "async-stream", "async-trait", - "atty", "aws-config", "aws-credential-types", "aws-sdk-cloudwatch", @@ -9767,6 +9766,7 @@ dependencies = [ "indoc", "infer 0.15.0", "inventory", + "is-terminal", "itertools 0.11.0", "k8s-openapi 0.18.0", "kube", diff --git a/Cargo.toml b/Cargo.toml index 3fbde1e5d2fd5..600b554e11b6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -340,7 +340,7 @@ mlua = { version = "0.9.1", default-features = false, features = ["lua54", "send windows-service = "0.6.0" [target.'cfg(unix)'.dependencies] -atty = { version = "0.2.14", default-features = false } +is-terminal = { version = "0.4", default-features = false } nix = { version = "0.26.2", default-features = false, features = ["socket", "signal"] } [build-dependencies] diff --git a/src/cli.rs b/src/cli.rs index 794ca3ade12e0..6c0408317b6f9 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -331,9 +331,10 @@ pub enum Color { impl Color { pub fn use_color(&self) -> bool { + use is_terminal::IsTerminal; match self { #[cfg(unix)] - Color::Auto => atty::is(atty::Stream::Stdout), + Color::Auto => std::io::stdout().is_terminal(), #[cfg(windows)] Color::Auto => false, // ANSI colors are not supported by cmd.exe Color::Always => true, diff --git a/src/test_util/mod.rs b/src/test_util/mod.rs index a58ef0bcf5369..ffd8505f76c79 100644 --- a/src/test_util/mod.rs +++ b/src/test_util/mod.rs @@ -122,7 +122,10 @@ pub fn next_addr_v6() -> SocketAddr { pub fn trace_init() { #[cfg(unix)] - let color = atty::is(atty::Stream::Stdout); + let color = { + use is_terminal::IsTerminal; + std::io::stdout().is_terminal() + }; // Windows: ANSI colors are not supported by cmd.exe // Color is false for everything except unix. #[cfg(not(unix))] diff --git a/vdev/Cargo.toml b/vdev/Cargo.toml index 636d4f98c0b6f..b3bd2bdc1d701 100644 --- a/vdev/Cargo.toml +++ b/vdev/Cargo.toml @@ -9,7 +9,7 @@ publish = false [dependencies] anyhow = "1.0.75" -atty = "0.2.14" +is-terminal = { version = "0.4" } cached = "0.46.0" chrono = { version = "0.4.31", default-features = false, features = ["serde", "clock"] } clap = { version = "4.4.7", features = ["derive"] } diff --git a/vdev/src/util.rs b/vdev/src/util.rs index 306ccd9c1c1b8..e5fcd781e525b 100644 --- a/vdev/src/util.rs +++ b/vdev/src/util.rs @@ -3,11 +3,12 @@ use std::process::{Command, Output}; use std::{collections::BTreeMap, fmt::Debug, fs, io::ErrorKind, path::Path}; use anyhow::{Context as _, Result}; +use is_terminal::IsTerminal; use once_cell::sync::Lazy; use serde::Deserialize; use serde_json::Value; -pub static IS_A_TTY: Lazy = Lazy::new(|| atty::is(atty::Stream::Stdout)); +pub static IS_A_TTY: Lazy = Lazy::new(|| std::io::stdout().is_terminal()); #[derive(Deserialize)] pub struct CargoTomlPackage {