Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace atty with is-terminal #246

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 134 additions & 11 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ pre-release-replacements = [
]

[features]
default = ["termcolor", "atty", "humantime", "regex"]
default = ["termcolor", "is-terminal", "humantime", "regex"]

[dependencies]
log = { version = "0.4.8", features = ["std"] }
regex = { version = "1.0.3", optional = true, default-features=false, features=["std", "perf"] }
termcolor = { version = "1.1.1", optional = true }
humantime = { version = "2.0.0", optional = true }
atty = { version = "0.2.5", optional = true }
is-terminal = { version = "0.4.0", optional = true }

[[test]]
name = "regexp_filter"
Expand Down
2 changes: 1 addition & 1 deletion ci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod permute;
mod task;

fn main() {
let features = ["termcolor", "humantime", "atty", "regex"];
let features = ["termcolor", "humantime", "is-terminal", "regex"];

// Run a default build
if !task::test(Default::default()) {
Expand Down
20 changes: 12 additions & 8 deletions src/fmt/writer/atty.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
/*
This internal module contains the terminal detection implementation.

If the `atty` crate is available then we use it to detect whether we're
attached to a particular TTY. If the `atty` crate is not available we
assume we're not attached to anything. This effectively prevents styles
from being printed.
If the `is-terminal` crate is available then we use it to detect whether
we're attached to a particular TTY. If the `is-terminal` crate is not
available we assume we're not attached to anything. This effectively
prevents styles from being printed.
*/

#[cfg(feature = "atty")]
#[cfg(feature = "is-terminal")]
mod imp {
use std::io::{stderr, stdout};

use is_terminal::IsTerminal;

pub(in crate::fmt) fn is_stdout() -> bool {
atty::is(atty::Stream::Stdout)
stdout().is_terminal()
}

pub(in crate::fmt) fn is_stderr() -> bool {
atty::is(atty::Stream::Stderr)
stderr().is_terminal()
}
}

#[cfg(not(feature = "atty"))]
#[cfg(not(feature = "is-terminal"))]
mod imp {
pub(in crate::fmt) fn is_stdout() -> bool {
false
Expand Down