Use std::io::IsTerminal instead of atty crate (#2066)
This commit is contained in:
parent
178d4e2190
commit
63ad7cc176
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -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",
|
||||||
|
@ -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"] }
|
||||||
|
20
src/color.rs
20
src/color.rs
@ -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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user