From 443d240f49e9f48756ee88e4cdc377f09d44454e Mon Sep 17 00:00:00 2001 From: George Pollard Date: Tue, 14 Mar 2023 17:10:21 +1300 Subject: [PATCH] fix(atty): Switch out `atty` for `is-terminal` (#229) --- Cargo.toml | 10 +++++----- src/handler.rs | 10 +++++----- src/handlers/theme.rs | 6 ++++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5a0e337..a10235c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,11 +19,11 @@ once_cell = "1.8.0" unicode-width = "0.1.9" owo-colors = { version = "3.0.0", optional = true } -atty = { version = "0.2.14", optional = true } +is-terminal = { version = "0.4.0", optional = true } textwrap = { version = "0.15.0", optional = true } -supports-hyperlinks = { version = "1.1.0", optional = true } -supports-color = { version = "1.1.1", optional = true } -supports-unicode = { version = "1.0.0", optional = true } +supports-hyperlinks = { version = "2.0.0", optional = true } +supports-color = { version = "2.0.0", optional = true } +supports-unicode = { version = "2.0.0", optional = true } backtrace = { version = "0.3.61", optional = true } terminal_size = { version = "0.1.17", optional = true } @@ -43,7 +43,7 @@ lazy_static = "1.4" default = [] fancy-no-backtrace = [ "owo-colors", - "atty", + "is-terminal", "textwrap", "terminal_size", "supports-hyperlinks", diff --git a/src/handler.rs b/src/handler.rs index 3aca572..e983a55 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -1,7 +1,5 @@ use std::fmt; -use atty::Stream; - use crate::protocol::Diagnostic; use crate::GraphicalReportHandler; use crate::GraphicalTheme; @@ -193,12 +191,14 @@ impl MietteHandlerOpts { let characters = match self.unicode { Some(true) => ThemeCharacters::unicode(), Some(false) => ThemeCharacters::ascii(), - None if supports_unicode::on(Stream::Stderr) => ThemeCharacters::unicode(), + None if supports_unicode::on(supports_unicode::Stream::Stderr) => { + ThemeCharacters::unicode() + } None => ThemeCharacters::ascii(), }; let styles = if self.color == Some(false) { ThemeStyles::none() - } else if let Some(color) = supports_color::on(Stream::Stderr) { + } else if let Some(color) = supports_color::on(supports_color::Stream::Stderr) { match self.rgb_colors { RgbColors::Always => ThemeStyles::rgb(), RgbColors::Preferred if color.has_16m => ThemeStyles::rgb(), @@ -257,7 +257,7 @@ impl MietteHandlerOpts { if let Some(linkify) = self.linkify { linkify } else { - supports_hyperlinks::on(Stream::Stderr) + supports_hyperlinks::on(supports_hyperlinks::Stream::Stderr) } } diff --git a/src/handlers/theme.rs b/src/handlers/theme.rs index e76a44d..0596e45 100644 --- a/src/handlers/theme.rs +++ b/src/handlers/theme.rs @@ -1,4 +1,4 @@ -use atty::Stream; +use is_terminal::IsTerminal; use owo_colors::Style; /** @@ -63,7 +63,9 @@ impl GraphicalTheme { impl Default for GraphicalTheme { fn default() -> Self { match std::env::var("NO_COLOR") { - _ if !atty::is(Stream::Stdout) || !atty::is(Stream::Stderr) => Self::ascii(), + _ if !std::io::stdout().is_terminal() || !std::io::stderr().is_terminal() => { + Self::ascii() + } Ok(string) if string != "0" => Self::unicode_nocolor(), _ => Self::unicode(), }