mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(diagnostics): check for terminal when displaying links (#6018)
fixes #5819
This commit is contained in:
parent
e3c8a12c0d
commit
a88504cefb
2 changed files with 12 additions and 16 deletions
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
/// origin file: https://github.com/zkat/miette/blob/75fea0935e495d0215518c80d32dd820910982e3/src/handlers/graphical.rs#L1
|
||||
use std::fmt::{self, Write};
|
||||
use std::io::IsTerminal;
|
||||
|
||||
use miette::{
|
||||
Diagnostic, LabeledSpan, ReportHandler, Severity, SourceCode, SourceSpan, SpanContents,
|
||||
|
|
@ -66,10 +67,11 @@ impl GraphicalReportHandler {
|
|||
/// Create a new `GraphicalReportHandler` with the default
|
||||
/// [`GraphicalTheme`]. This will use both unicode characters and colors.
|
||||
pub fn new() -> Self {
|
||||
let is_terminal = std::io::stdout().is_terminal() && std::io::stderr().is_terminal();
|
||||
Self {
|
||||
links: LinkStyle::Link,
|
||||
links: if is_terminal { LinkStyle::Link } else { LinkStyle::Text },
|
||||
termwidth: 400,
|
||||
theme: GraphicalTheme::default(),
|
||||
theme: GraphicalTheme::new(is_terminal),
|
||||
footer: None,
|
||||
context_lines: 1,
|
||||
tab_width: 4,
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
/// origin file: https://github.com/zkat/miette/blob/75fea0935e495d0215518c80d32dd820910982e3/src/handlers/theme.rs
|
||||
use std::io::IsTerminal;
|
||||
|
||||
use miette::ThemeCharacters;
|
||||
use owo_colors::Style;
|
||||
|
||||
|
|
@ -32,6 +30,14 @@ pub struct GraphicalTheme {
|
|||
}
|
||||
|
||||
impl GraphicalTheme {
|
||||
pub fn new(is_terminal: bool) -> Self {
|
||||
match std::env::var("NO_COLOR") {
|
||||
_ if !is_terminal => Self::none(),
|
||||
Ok(string) if string != "0" => Self::unicode_nocolor(),
|
||||
_ => Self::unicode(),
|
||||
}
|
||||
}
|
||||
|
||||
/// ASCII-art-based graphical drawing, with ANSI styling.
|
||||
pub fn ascii() -> Self {
|
||||
Self { characters: ThemeCharacters::ascii(), styles: ThemeStyles::ansi() }
|
||||
|
|
@ -63,18 +69,6 @@ impl GraphicalTheme {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for GraphicalTheme {
|
||||
fn default() -> Self {
|
||||
match std::env::var("NO_COLOR") {
|
||||
_ if !std::io::stdout().is_terminal() || !std::io::stderr().is_terminal() => {
|
||||
Self::none()
|
||||
}
|
||||
Ok(string) if string != "0" => Self::unicode_nocolor(),
|
||||
_ => Self::unicode(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Styles for various parts of graphical rendering for the
|
||||
[`GraphicalReportHandler`](crate::GraphicalReportHandler).
|
||||
|
|
|
|||
Loading…
Reference in a new issue