Skip to content

Commit

Permalink
Use std::io::IsTerminal instead of atty crate (#2066)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored May 20, 2024
1 parent 178d4e2 commit 63ad7cc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
20 changes: 10 additions & 10 deletions src/color.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
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 {
fn restyle(self, style: Style) -> Self {
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
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
}

Expand All @@ -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,
}
}
}

0 comments on commit 63ad7cc

Please sign in to comment.