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

Replace atty with is-terminal. #1151

Merged
merged 1 commit into from
Nov 22, 2022
Merged
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
133 changes: 131 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dev = []
members = ["xtask"]

[dependencies]
atty = "0.2"
is-terminal = "0.4.0"
Alexhuszagh marked this conversation as resolved.
Show resolved Hide resolved
clap = { version = "4.0", features = ["derive"] }
color-eyre = { version = "0.6.2", default-features = false, features = ["track-caller"] }
eyre = "0.6"
Expand Down
6 changes: 5 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ vulnerability = "deny"
unmaintained = "deny"
notice = "deny"
unsound = "deny"
ignore = []
# FIXME: remove this if/when clap changes to is-terminal, atty is
# patched, or we migrated to an MSRV of 1.66.0.
ignore = [
"RUSTSEC-2021-0145",
]

[bans]
multiple-versions = "deny"
Expand Down
25 changes: 18 additions & 7 deletions src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::str::FromStr;

use crate::config::bool_from_envvar;
use crate::errors::Result;
use is_terminal::IsTerminal;
use owo_colors::{self, OwoColorize};

// get the prefix for stderr messages
Expand Down Expand Up @@ -441,32 +442,42 @@ fn get_verbosity(
}

pub trait Stream {
const TTY: atty::Stream;
type TTY: IsTerminal;
const OWO: owo_colors::Stream;

#[must_use]
fn is_atty() -> bool {
atty::is(Self::TTY)
}
fn is_atty() -> bool;

fn owo(&self) -> owo_colors::Stream {
Self::OWO
}
}

impl Stream for io::Stdin {
const TTY: atty::Stream = atty::Stream::Stdin;
type TTY = io::Stdin;
const OWO: owo_colors::Stream = owo_colors::Stream::Stdin;

fn is_atty() -> bool {
io::stdin().is_terminal()
}
}

impl Stream for io::Stdout {
const TTY: atty::Stream = atty::Stream::Stdout;
type TTY = io::Stdout;
const OWO: owo_colors::Stream = owo_colors::Stream::Stdout;

fn is_atty() -> bool {
io::stdout().is_terminal()
}
}

impl Stream for io::Stderr {
const TTY: atty::Stream = atty::Stream::Stderr;
type TTY = io::Stderr;
const OWO: owo_colors::Stream = owo_colors::Stream::Stderr;

fn is_atty() -> bool {
io::stderr().is_terminal()
}
}

pub fn default_ident() -> usize {
Expand Down