Skip to content

Commit

Permalink
Merge #1151
Browse files Browse the repository at this point in the history
1151: Replace atty with is-terminal. r=Emilgardis a=Alexhuszagh

Although this doesn't affect cross (since we do not use custom allocators), this address [rustsec-1457](rustsec/advisory-db#1457).

Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
  • Loading branch information
bors[bot] and Alexhuszagh authored Nov 22, 2022
2 parents ab99baf + 159caaa commit 6abac22
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 11 deletions.
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"
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

0 comments on commit 6abac22

Please sign in to comment.