From 5bd76fd11b9e992c2b52ed2047cb473513541807 Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Tue, 6 Dec 2022 11:24:53 -0500 Subject: [PATCH] Replace `is-terminal` with `supports-color` and make `auto` default for color --- Cargo.toml | 2 +- src/bin/hexyl.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f0c2769..76e00e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,8 @@ edition = "2021" anstyle = "0.2" anyhow = "1.0" const_format = "0.2" -is-terminal = "0.4" libc = "0.2" +supports-color = "1" thiserror = "1.0" terminal_size = "0.2" diff --git a/src/bin/hexyl.rs b/src/bin/hexyl.rs index 3ecf1b0..32a231b 100644 --- a/src/bin/hexyl.rs +++ b/src/bin/hexyl.rs @@ -9,8 +9,6 @@ use std::num::{NonZeroI64, NonZeroU64, NonZeroU8}; use clap::builder::ArgPredicate; use clap::{crate_name, crate_version, Arg, ArgAction, ColorChoice, Command}; -use is_terminal::IsTerminal; - use anyhow::{anyhow, Context, Result}; use const_format::formatcp; @@ -106,7 +104,7 @@ fn run() -> Result<()> { .value_name("WHEN") .value_parser(["always", "auto", "never"]) .default_value_if("plain", ArgPredicate::IsPresent, Some("never")) - .default_value("always") + .default_value("auto") .help( "When to use colors. The auto-mode only displays colors if the output \ goes to an interactive terminal", @@ -293,8 +291,10 @@ fn run() -> Result<()> { let show_color = match matches.get_one::("color").map(String::as_ref) { Some("never") => false, - Some("auto") => std::io::stdout().is_terminal(), - _ => true, + Some("always") => true, + _ => supports_color::on_cached(supports_color::Stream::Stdout) + .map(|level| level.has_basic) + .unwrap_or(false), }; let border_style = match matches.get_one::("border").map(String::as_ref) {