Use std::io::IsTerminal instead of atty crate (#2066)

This commit is contained in:
Casey Rodarmor 2024-05-20 16:42:15 -07:00 committed by GitHub
parent 178d4e2190
commit 63ad7cc176
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 12 deletions

1
Cargo.lock generated
View File

@ -517,7 +517,6 @@ name = "just"
version = "1.26.0" version = "1.26.0"
dependencies = [ dependencies = [
"ansi_term", "ansi_term",
"atty",
"blake3", "blake3",
"camino", "camino",
"clap 4.5.4", "clap 4.5.4",

View File

@ -19,7 +19,6 @@ members = [".", "crates/*"]
[dependencies] [dependencies]
ansi_term = "0.12.0" ansi_term = "0.12.0"
atty = "0.2.0"
blake3 = { version = "1.5.0", features = ["rayon", "mmap"] } blake3 = { version = "1.5.0", features = ["rayon", "mmap"] }
camino = "1.0.4" camino = "1.0.4"
clap = { version = "4.0.0", features = ["env", "wrap_help"] } clap = { version = "4.0.0", features = ["env", "wrap_help"] }

View File

@ -1,14 +1,14 @@
use { use {
super::*, super::*,
ansi_term::{ANSIGenericString, Color::*, Prefix, Style, Suffix}, ansi_term::{ANSIGenericString, Color::*, Prefix, Style, Suffix},
atty::Stream, std::io::{self, IsTerminal},
}; };
#[derive(Copy, Clone, Debug, PartialEq)] #[derive(Copy, Clone, Debug, PartialEq)]
pub(crate) struct Color { pub(crate) struct Color {
use_color: UseColor, is_terminal: bool,
atty: bool,
style: Style, style: Style,
use_color: UseColor,
} }
impl Color { impl Color {
@ -16,9 +16,9 @@ impl Color {
Self { style, ..self } Self { style, ..self }
} }
fn redirect(self, stream: Stream) -> Self { fn redirect(self, stream: impl IsTerminal) -> Self {
Self { Self {
atty: atty::is(stream), is_terminal: stream.is_terminal(),
..self ..self
} }
} }
@ -53,11 +53,11 @@ impl Color {
} }
pub(crate) fn stderr(self) -> Self { pub(crate) fn stderr(self) -> Self {
self.redirect(Stream::Stderr) self.redirect(io::stderr())
} }
pub(crate) fn stdout(self) -> Self { pub(crate) fn stdout(self) -> Self {
self.redirect(Stream::Stdout) self.redirect(io::stdout())
} }
pub(crate) fn context(self) -> Self { pub(crate) fn context(self) -> Self {
@ -116,7 +116,7 @@ impl Color {
match self.use_color { match self.use_color {
UseColor::Always => true, UseColor::Always => true,
UseColor::Never => false, UseColor::Never => false,
UseColor::Auto => self.atty, UseColor::Auto => self.is_terminal,
} }
} }
@ -136,9 +136,9 @@ impl Color {
impl Default for Color { impl Default for Color {
fn default() -> Self { fn default() -> Self {
Self { Self {
use_color: UseColor::Auto, is_terminal: false,
atty: false,
style: Style::new(), style: Style::new(),
use_color: UseColor::Auto,
} }
} }
} }