Skip to content

Commit

Permalink
fix(atty): Switch out atty for is-terminal (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
Porges committed Mar 14, 2023
1 parent ed486c9 commit 443d240
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -43,7 +43,7 @@ lazy_static = "1.4"
default = []
fancy-no-backtrace = [
"owo-colors",
"atty",
"is-terminal",
"textwrap",
"terminal_size",
"supports-hyperlinks",
Expand Down
10 changes: 5 additions & 5 deletions src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::fmt;

use atty::Stream;

use crate::protocol::Diagnostic;
use crate::GraphicalReportHandler;
use crate::GraphicalTheme;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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)
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/handlers/theme.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use atty::Stream;
use is_terminal::IsTerminal;
use owo_colors::Style;

/**
Expand Down Expand Up @@ -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(),
}
Expand Down

0 comments on commit 443d240

Please sign in to comment.