Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Getting raw ansi codes in windows terminal #80

Open
mainrs opened this issue Mar 17, 2021 · 6 comments
Open

Getting raw ansi codes in windows terminal #80

mainrs opened this issue Mar 17, 2021 · 6 comments
Labels
bug Something isn't working help wanted Extra attention is needed question Further information is requested

Comments

@mainrs
Copy link

mainrs commented Mar 17, 2021

Not sure why this happens as I always thought Windows terminal supports ANSI escape codes. Here is an example output:

$ cargo run
Error:
   0: ←[91mMisformatted label definition file. Make sure the file is valid json!←[0m
   1: ←[91mmissing field `templates` at line 104 column 1←[0m

Location:
   ←[35mC:$HOME\.cargo\registry\src\github.com-1ecc6299db9ec823\gh-labels-cli-0.1.8\src\file.rs←[0m:←[35m53←[0m

Backtrace omitted.
Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

Windows Terminal Preview
Version: 1.7.572.0
rustc 1.50.0 (cb75ad5db 2021-02-10)
color-eyre 0.5.10
eyre 0.6.5

@yaahc
Copy link
Collaborator

yaahc commented Mar 17, 2021

Is it only color-eyre that is doing this? I'm curious to see if you use other cli tools that colorize their output, do their color codes show up verbatim or does it still work? And if so are they outputting ANSI escape codes or are they using windows APIs?

I don't have access to Windows Terminal Preview atm so it might take me a while to get around to reproducing this myself.

@mainrs
Copy link
Author

mainrs commented Mar 17, 2021

Crates depending on termcolor:

  • cargo
  • ripgrep

Crates depending on colored:

  • color-eyre
  • cargo-make
  • cargo-geiger (does not compile)

Crates depending on owo-colors:

  • hex-rgb

Looks like it's only color-eyre. I made sure that I've called color_eyre::install() :)

Windows Terminal: https://github.com/microsoft/terminal/releases/tag/v1.7.572.0

@yaahc
Copy link
Collaborator

yaahc commented Mar 17, 2021

wow, other crates depending on owo-colors worked??? What version of owo-colors are they depending on?

@mainrs
Copy link
Author

mainrs commented Mar 18, 2021

color-eyre: ^1.2.1
hex-rgb: ^1.1.3

If not installed with the --locked flag they both would resolve to the newest minor which would be 1.3.0, which makes this even weirder... 1.3.0 added support for tty checking. It's gated behind a feature flag though.

Edit: I did more testing. I have a crate that hard-encodes ANSI colored strings into it:

pub const INFO_SYMBOL: Emoji = Emoji::new("\u{1b}[34mℹ\u{1b}[0m", "\u{1b}[34mi\u{1b}[0m");

And these fail as well:

$ gh labels -r https://github.com/SirWindfield/terminal-spinners-rs update --purge[34mℹ←[0m Purging all 24 labels...
←[34mℹ←[0m Repository has 0 labels, creating 24 and updating 0...

I am so clueless... I have no clue why one CLI (hex-rgb) works but the other library (color-eyre) does not... For the sake of completeness I also tested on the newest stable release of WT (Version: 1.6.10571.0), same behavior.

@yaahc yaahc added bug Something isn't working help wanted Extra attention is needed question Further information is requested labels Feb 4, 2022
truelossless added a commit to truelossless/cugparck that referenced this issue Jul 27, 2022
- add required nvcuda.dll for those who don't have it
- lower CUDA (therefore nvidia driver) requirements
- untrack PTX

I am aware of an issue with ANSI escape sequences showing in windows
terminals. This seems related to
eyre-rs/color-eyre#80 and the owo_colors crate.

Not sure how to fix that. Maybe switch to anyhow and use crossterm
instead of owo colors would work, but we would loose the colorful error
reports.
@sclu1034
Copy link

sclu1034 commented Nov 11, 2022

I'm running into this issue as well, except cross-compiled on Linux, running through Wine:

cargo run --target x86_64-pc-windows-gnu --example=usage
# or if you don't use a binfmt
cargo build --target x86_64-pc-windows-gnu --example=usage
wine ./target/x86_64-pc-windows-gnu/debug/examples/usage.exe

Interestingly, the tracing event log is perfectly colored, and bold and italics always work. Only color codes in the error message and span trace are messed up.

image

Version: 4a7b4d6

@FlareFlo
Copy link

Any temporary fix to this, such as conditionally disabling color on windows? Ive looked but not found a way to disable color for windows, unless i pull in regular eyre just for said windows build.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants