From 63ad7cc17688c72f3487a7d6ae4c3009ce638be6 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 20 May 2024 16:42:15 -0700 Subject: [PATCH] Use std::io::IsTerminal instead of atty crate (#2066) --- Cargo.lock | 1 - Cargo.toml | 1 - src/color.rs | 20 ++++++++++---------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 92fabbd..09cfa01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -517,7 +517,6 @@ name = "just" version = "1.26.0" dependencies = [ "ansi_term", - "atty", "blake3", "camino", "clap 4.5.4", diff --git a/Cargo.toml b/Cargo.toml index b52c780..f932357 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,6 @@ members = [".", "crates/*"] [dependencies] ansi_term = "0.12.0" -atty = "0.2.0" blake3 = { version = "1.5.0", features = ["rayon", "mmap"] } camino = "1.0.4" clap = { version = "4.0.0", features = ["env", "wrap_help"] } diff --git a/src/color.rs b/src/color.rs index 11ab6d4..f477d4e 100644 --- a/src/color.rs +++ b/src/color.rs @@ -1,14 +1,14 @@ use { super::*, ansi_term::{ANSIGenericString, Color::*, Prefix, Style, Suffix}, - atty::Stream, + std::io::{self, IsTerminal}, }; #[derive(Copy, Clone, Debug, PartialEq)] pub(crate) struct Color { - use_color: UseColor, - atty: bool, + is_terminal: bool, style: Style, + use_color: UseColor, } impl Color { @@ -16,9 +16,9 @@ impl Color { Self { style, ..self } } - fn redirect(self, stream: Stream) -> Self { + fn redirect(self, stream: impl IsTerminal) -> Self { Self { - atty: atty::is(stream), + is_terminal: stream.is_terminal(), ..self } } @@ -53,11 +53,11 @@ impl Color { } pub(crate) fn stderr(self) -> Self { - self.redirect(Stream::Stderr) + self.redirect(io::stderr()) } pub(crate) fn stdout(self) -> Self { - self.redirect(Stream::Stdout) + self.redirect(io::stdout()) } pub(crate) fn context(self) -> Self { @@ -116,7 +116,7 @@ impl Color { match self.use_color { UseColor::Always => true, UseColor::Never => false, - UseColor::Auto => self.atty, + UseColor::Auto => self.is_terminal, } } @@ -136,9 +136,9 @@ impl Color { impl Default for Color { fn default() -> Self { Self { - use_color: UseColor::Auto, - atty: false, + is_terminal: false, style: Style::new(), + use_color: UseColor::Auto, } } }