From 3f30d765055859146bb0e453315a4ac77de504d7 Mon Sep 17 00:00:00 2001 From: George Pollard Date: Tue, 20 Dec 2022 20:46:54 +0000 Subject: [PATCH] Switch out `atty` for `is-terminal` --- Cargo.toml | 10 +++++----- src/handler.rs | 8 +++----- src/handlers/theme.rs | 6 ++++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5a0e337..79780f9 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.1", 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 = { git = "https://github.com/Porges/supports-hyperlinks", optional = true } +supports-color = { git = "https://github.com/zkat/supports-color", optional = true } +supports-unicode = { git = "https://github.com/Porges/supports-unicode", 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..09545ce 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,12 @@ 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(&std::io::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 +255,7 @@ impl MietteHandlerOpts { if let Some(linkify) = self.linkify { linkify } else { - supports_hyperlinks::on(Stream::Stderr) + supports_hyperlinks::on(&std::io::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(), }