Skip to content

Commit

Permalink
Replace atty with is-terminal (#506)
Browse files Browse the repository at this point in the history
* Replace atty with is-terminal

* Remove advisory

---------

Co-authored-by: Jake Shadle <jake.shadle@embark-studios.com>
  • Loading branch information
tottoto and Jake-Shadle authored Apr 6, 2023
1 parent d37423a commit d485903
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 34 deletions.
22 changes: 1 addition & 21 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 @@ -47,7 +47,7 @@ anyhow = "1.0"
# Used for detecting the license type of a file
askalono = "0.4"
# Used to detect if an output stream is a TTY to control default coloring
atty = "0.2"
is-terminal = "0.4.6"
# Used to track various things during check runs
bitvec = { version = "1.0", features = ["alloc"] }
# Allows us to do eg cargo metadata operations without relying on an external cargo
Expand Down
3 changes: 0 additions & 3 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ unmaintained = "deny"
notice = "deny"
unsound = "deny"
ignore = [
# potential unaligned pointer read on windows. Doesn't happen in practice, don't
# care
"RUSTSEC-2021-0145",
# rmp-serde used by askalono for the cache files, these are always utf-8 so
# the advisory is not relevant
"RUSTSEC-2022-0092",
Expand Down
3 changes: 2 additions & 1 deletion src/cargo-deny/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use cargo_deny::{
},
licenses, sources, CheckCtx,
};
use is_terminal::IsTerminal as _;
use log::error;
use serde::Deserialize;
use std::{path::PathBuf, time::Instant};
Expand Down Expand Up @@ -471,7 +472,7 @@ pub(crate) fn cmd(

let colorize = log_ctx.format == crate::Format::Human
&& match log_ctx.color {
crate::Color::Auto => atty::is(atty::Stream::Stderr),
crate::Color::Auto => std::io::stderr().is_terminal(),
crate::Color::Always => true,
crate::Color::Never => false,
};
Expand Down
10 changes: 5 additions & 5 deletions src/cargo-deny/common.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::path::PathBuf;

use cargo_deny::{
diag::{self, FileId, Files, Severity},
licenses::LicenseStore,
};
use is_terminal::IsTerminal;
use std::path::PathBuf;

pub(crate) fn load_license_store() -> Result<LicenseStore, anyhow::Error> {
log::debug!("loading license store...");
Expand Down Expand Up @@ -272,12 +272,12 @@ pub fn log_level_to_severity(log_level: log::LevelFilter) -> Option<Severity> {
use codespan_reporting::term::{self, termcolor::ColorChoice};
use std::io::Write;

fn color_to_choice(color: crate::Color, stream: atty::Stream) -> ColorChoice {
fn color_to_choice(color: crate::Color, stream: impl IsTerminal) -> ColorChoice {
match color {
crate::Color::Auto => {
// The termcolor crate doesn't check the stream to see if it's a TTY
// which doesn't really fit with how the rest of the coloring works
if atty::is(stream) {
if stream.is_terminal() {
ColorChoice::Auto
} else {
ColorChoice::Never
Expand Down Expand Up @@ -476,7 +476,7 @@ impl<'a> DiagPrinter<'a> {
crate::Format::Human => {
let stream = term::termcolor::StandardStream::stderr(color_to_choice(
ctx.color,
atty::Stream::Stderr,
std::io::stderr(),
));

Self {
Expand Down
3 changes: 2 additions & 1 deletion src/cargo-deny/list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{Context, Error};
use cargo_deny::{diag::Files, licenses, Kid};
use is_terminal::IsTerminal as _;
use nu_ansi_term::Color;
use serde::Serialize;
use std::path::PathBuf;
Expand Down Expand Up @@ -250,7 +251,7 @@ pub fn cmd(
let color = match log_ctx.color {
crate::Color::Always => true,
crate::Color::Never => false,
crate::Color::Auto => atty::is(atty::Stream::Stdout),
crate::Color::Auto => std::io::stdout().is_terminal(),
};

match args.layout {
Expand Down
3 changes: 2 additions & 1 deletion src/cargo-deny/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use anyhow::{bail, Context, Error};
use clap::{Parser, Subcommand, ValueEnum};
use is_terminal::IsTerminal as _;
use std::path::PathBuf;

mod check;
Expand Down Expand Up @@ -231,7 +232,7 @@ fn real_main() -> Result<(), Error> {
let log_level = args.log_level;

let color = match args.color {
Color::Auto => atty::is(atty::Stream::Stderr),
Color::Auto => std::io::stderr().is_terminal(),
Color::Always => true,
Color::Never => false,
};
Expand Down
3 changes: 2 additions & 1 deletion src/cargo-deny/stats.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::Format;
use is_terminal::IsTerminal as _;
use nu_ansi_term::Color;
use serde::Serialize;

Expand Down Expand Up @@ -46,7 +47,7 @@ pub(crate) fn print_stats(
let mut summary = String::new();

let color = match color {
crate::Color::Auto => atty::is(atty::Stream::Stdout),
crate::Color::Auto => std::io::stdout().is_terminal(),
crate::Color::Always => true,
crate::Color::Never => false,
};
Expand Down

0 comments on commit d485903

Please sign in to comment.