-
Notifications
You must be signed in to change notification settings - Fork 133
Fix colors on Windows (#749) #768
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
Conversation
Calling the `hSupportsANSIWithoutEmulation` function on Windows 10+ enables terminal colors where supported. https://hackage.haskell.org/package/ansi-terminal-0.11/docs/System-Console-ANSI.html#v:hSupportsANSIWithoutEmulation Also has the added benefit that (on Windows), the ANSI codes aren't present when output is redirected to a text file.
Oh I was just rebasing at the same time you were :) Will wait for CI then look at any errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left small suggestions but otherwise looks great! 👏
@f-f Ok as shown by the failing tests, this actually produces a change in behavior. For all platforms now, if the output is directed into a file, the color codes are never included, even without the Is this change desired? If not, we can instead just call the |
Good question. It feels like the new behaviour should be more correct, but I don't have a strong opinion on this. |
I can't find any definitive recommendation on this, but yeah my feeling too is that logfiles should be free from the color codes. After investigating, this is indeed what the purs compiler does (as well as respecting |
Great then, let's move on with this! |
Yeah I'm just working on making all the tests pass |
Tests are now passing; I stripped the color codes from the relevant test fixtures. While we were here I also came across the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is perfect now, great work! 👏👏
Nice work @stkb! |
Looking through the Stack source code lead me to the
hSupportsANSIWithoutEmulation
function. Calling this on Windows 10+ returnsJust True
but also enables the processing of the Ansi control codes as a side effect.This change also has the added benefit that (on Windows), the ANSI codes aren't present when output is redirected to a text file.
Code is just proof-of concept; feel free to modify as you wish. Haven't tested on *nix but it's working on Windows for me.