Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions crates/oxc_diagnostics/src/graphic_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 8 additions & 14 deletions crates/oxc_diagnostics/src/graphical_theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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() }
Expand Down Expand Up @@ -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).
Expand Down