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

Ansi colour codes emitted on Powershell #15

Closed
Michael-F-Bryan opened this issue Oct 31, 2017 · 7 comments
Closed

Ansi colour codes emitted on Powershell #15

Michael-F-Bryan opened this issue Oct 31, 2017 · 7 comments

Comments

@Michael-F-Bryan
Copy link

I've just reinstalled my work computer and it looks like pretty_assertions is now printing ansi codes instead of using the native windows mechanism for terminal colours. It's probably something to do with my environment, but do you have any idea why this may be happening even though cargo is able to print colours just fine?

Here's a screenshot to show the output.

image

cc: #1

@colin-kiegel
Copy link
Collaborator

@Michael-F-Bryan: Thx for the report

  • Did it work before for you?
  • Does it work with older versions of pretty_assertions?

@Michael-F-Bryan
Copy link
Author

Yeah, I used to use it all the time at work although I've had my Cargo.toml set to use 0.4 for a month or so now. I just tried version 0.3.4 and powershell is still printing the escape codes, meaning it's probably something to do with my environment and not your library. This is on a clean install of Windows 10 though, so I'm not 100% sure what the difference could be.

@Michael-F-Bryan
Copy link
Author

@colin-kiegel, what are your thoughts on swapping to the term crate for rendering colours instead of ansi_term? For some reason PowerShell has decided it doesn't want to interpret ANSI escape codes again. I can always hack around this on my side, but it seems like a better solution in the long term would be to use a cross-platform terminal library.

@colin-kiegel
Copy link
Collaborator

@Michael-F-Bryan Sounds like a good idea to me. Feel free to send me a PR, if you want to. ;-)

@colin-kiegel
Copy link
Collaborator

this should be fixed by #28 now.

@Mingun
Copy link

Mingun commented May 17, 2022

Unfortunately, this still an issue on some machines. I have the some problem as topicstarter -- cargo output is colored, but pretty_assertions outputs ANSI codes instead. This happens only in VSCode integrated terminal (using PowerShell 7.2.0) and only on Windows 7 (Windows 10 and Windows 11 are fine). When I run tests in PowerShell console, output is colored as expected:
The same output in VSCode and PowerShell in ConEmu
Any thoughts, how to fix that?

@tommilligan
Copy link
Collaborator

We use ansi_term internally for string styling. My guess would be the specific terminal you're using simply doesn't support ANSI codes.

I think the most likely workaround would be to detect and disable ANSI codes if they're not supported, as here. Alternatively, we could use a different library that can already cope with the environment you describe (and use whatever colour codes are required).

I don't personally have an interest in fixing this or the environment to test it in, but happy to review any fixes from affected users.

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

No branches or pull requests

4 participants