mirror of https://github.com/zkat/miette.git
fix(atty): Switch out `atty` for `is-terminal` (#229)
This commit is contained in:
parent
ed486c959d
commit
443d240f49
10
Cargo.toml
10
Cargo.toml
|
|
@ -19,11 +19,11 @@ once_cell = "1.8.0"
|
||||||
unicode-width = "0.1.9"
|
unicode-width = "0.1.9"
|
||||||
|
|
||||||
owo-colors = { version = "3.0.0", optional = true }
|
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 }
|
textwrap = { version = "0.15.0", optional = true }
|
||||||
supports-hyperlinks = { version = "1.1.0", optional = true }
|
supports-hyperlinks = { version = "2.0.0", optional = true }
|
||||||
supports-color = { version = "1.1.1", optional = true }
|
supports-color = { version = "2.0.0", optional = true }
|
||||||
supports-unicode = { version = "1.0.0", optional = true }
|
supports-unicode = { version = "2.0.0", optional = true }
|
||||||
backtrace = { version = "0.3.61", optional = true }
|
backtrace = { version = "0.3.61", optional = true }
|
||||||
terminal_size = { version = "0.1.17", optional = true }
|
terminal_size = { version = "0.1.17", optional = true }
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ lazy_static = "1.4"
|
||||||
default = []
|
default = []
|
||||||
fancy-no-backtrace = [
|
fancy-no-backtrace = [
|
||||||
"owo-colors",
|
"owo-colors",
|
||||||
"atty",
|
"is-terminal",
|
||||||
"textwrap",
|
"textwrap",
|
||||||
"terminal_size",
|
"terminal_size",
|
||||||
"supports-hyperlinks",
|
"supports-hyperlinks",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use atty::Stream;
|
|
||||||
|
|
||||||
use crate::protocol::Diagnostic;
|
use crate::protocol::Diagnostic;
|
||||||
use crate::GraphicalReportHandler;
|
use crate::GraphicalReportHandler;
|
||||||
use crate::GraphicalTheme;
|
use crate::GraphicalTheme;
|
||||||
|
|
@ -193,12 +191,14 @@ impl MietteHandlerOpts {
|
||||||
let characters = match self.unicode {
|
let characters = match self.unicode {
|
||||||
Some(true) => ThemeCharacters::unicode(),
|
Some(true) => ThemeCharacters::unicode(),
|
||||||
Some(false) => ThemeCharacters::ascii(),
|
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(),
|
None => ThemeCharacters::ascii(),
|
||||||
};
|
};
|
||||||
let styles = if self.color == Some(false) {
|
let styles = if self.color == Some(false) {
|
||||||
ThemeStyles::none()
|
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 {
|
match self.rgb_colors {
|
||||||
RgbColors::Always => ThemeStyles::rgb(),
|
RgbColors::Always => ThemeStyles::rgb(),
|
||||||
RgbColors::Preferred if color.has_16m => ThemeStyles::rgb(),
|
RgbColors::Preferred if color.has_16m => ThemeStyles::rgb(),
|
||||||
|
|
@ -257,7 +257,7 @@ impl MietteHandlerOpts {
|
||||||
if let Some(linkify) = self.linkify {
|
if let Some(linkify) = self.linkify {
|
||||||
linkify
|
linkify
|
||||||
} else {
|
} else {
|
||||||
supports_hyperlinks::on(Stream::Stderr)
|
supports_hyperlinks::on(supports_hyperlinks::Stream::Stderr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use atty::Stream;
|
use is_terminal::IsTerminal;
|
||||||
use owo_colors::Style;
|
use owo_colors::Style;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -63,7 +63,9 @@ impl GraphicalTheme {
|
||||||
impl Default for GraphicalTheme {
|
impl Default for GraphicalTheme {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
match std::env::var("NO_COLOR") {
|
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(),
|
Ok(string) if string != "0" => Self::unicode_nocolor(),
|
||||||
_ => Self::unicode(),
|
_ => Self::unicode(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue