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

Uses ANSI escape codes in dumb terminal in Sublime Text #2214

Closed
kornelski opened this issue Jul 9, 2022 · 3 comments
Closed

Uses ANSI escape codes in dumb terminal in Sublime Text #2214

kornelski opened this issue Jul 9, 2022 · 3 comments

Comments

@kornelski
Copy link
Contributor

Bug Report

Sublime Text 4 has a "Build" feature which can launch Rust/Cargo programs and redirect their output to its internal log viewer. This log is only in plain text, without any support for ANSI escape codes. It prints escape codes literally, making log output look messy.

fn main() {
    tracing_subscriber::fmt::init();
    tracing::info!("hello");
}

in Sublime's log looks like:

<0x1b>[2m2022-07-09T21:11:30.802562Z<0x1b>[0m <0x1b>[32m INFO<0x1b>[0m <0x1b>[2mtraa<0x1b>[0m<0x1b>[2m:<0x1b>[0m hello

Sublime does not set any env variables. There's no TERM. It has __CFBundleIdentifier env var set to com.sublimetext.4.

It would be nice if tracing_subscriber could detect if the terminal supports color before using ANSI codes, or at least detect that it's Sublime and it doesn't support them.

Version

tracing v0.1.35
tracing-subscriber v0.3.14
ansi_term v0.12.1

Platform

macOS 12.5

@DesmondWillowbrook
Copy link
Contributor

Huh, it seems that tracing_subscriber doesn't conduct any checks if the stream it's writing to actually supports color, which seems like an oversight. It just directly uses the ansi_term crate directly. Something like

could remedy the situation.

@stefnotch
Copy link

supports_color would be amazing, but there's a tricky trade-off there. We could use

  • Version 2, and accept all the extra dependencies that come with it
  • Version 3, and accept the MSRV of 1.70.0

https://github.com/zkat/supports-color/blob/main/CHANGELOG.md

My currently preferred option is waiting.

@davidbarsky
Copy link
Member

Given that we now do these checks, this issue can be safely closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants