Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NO_COLOR is printing ansi in non-terminals #380

Closed
Boshen opened this issue Jun 11, 2024 · 1 comment · Fixed by #381
Closed

NO_COLOR is printing ansi in non-terminals #380

Boshen opened this issue Jun 11, 2024 · 1 comment · Fixed by #381
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Boshen
Copy link
Contributor

Boshen commented Jun 11, 2024

Background: oxc-project/oxc#3539

Currently, if you use oxc_diagnostics with GraphicalReportHandler, and you print to a non-terminal, the output will contain color escape codes, even with NO_COLOR=1. This is because if stdout or stderr are not a terminal, GraphicalTheme::default() will return GraphicalTheme::ascii() regardless of the NO_COLOR value, and ascii() does have colors. This means that when printing to a non-terminal, there is no way to turn off the color escapes.

When printing to a non-terminal, you usually don't want color output, so presumably the default GraphicalTheme on non-terminals should be GraphicalTheme::none(). But in some cases it might be useful to enable color, even if not by default. Maybe FORCE_COLOR could be used in that case.

match std::env::var("NO_COLOR") {
_ if !std::io::stdout().is_terminal() || !std::io::stderr().is_terminal() => {
Self::ascii()
}

When it's non-terminal, Self::ascii()

/// ASCII-art-based graphical drawing, with ANSI styling.
pub fn ascii() -> Self {
Self {
characters: ThemeCharacters::ascii(),
styles: ThemeStyles::ansi(),
}
}

still uses ansi colors.

If the intention of NO_COLOR is to always not print ansi color codes, I can PR a change to GraphicalTheme::none().

Boshen added a commit to oxc-project/oxc that referenced this issue Jun 11, 2024

Verified

This commit was signed with the committer’s verified signature.
Boshen Boshen
closes #3539

upstream issue zkat/miette#380
Boshen added a commit to oxc-project/oxc that referenced this issue Jun 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
closes #3539

upstream issue zkat/miette#380
@zkat
Copy link
Owner

zkat commented Jun 11, 2024

yeah uh, that seems like a bug.

@zkat zkat added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Jun 11, 2024
Boshen added a commit to Boshen/miette that referenced this issue Jun 11, 2024

Verified

This commit was signed with the committer’s verified signature.
Boshen Boshen
closes zkat#380
Boshen added a commit to Boshen/miette that referenced this issue Jun 11, 2024

Verified

This commit was signed with the committer’s verified signature.
Boshen Boshen
closes zkat#380
@zkat zkat closed this as completed in #381 Jun 11, 2024
zkat pushed a commit that referenced this issue Jun 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…inals (#381)

Fixes: #380
Boshen added a commit to oxc-project/oxc-miette that referenced this issue Oct 27, 2024

Verified

This commit was signed with the committer’s verified signature.
Boshen Boshen
…inals (#381)

Fixes: zkat/miette#380
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants