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

Color codes garble output in PowerShell #6

Closed
corneliusweig opened this issue Feb 28, 2019 · 2 comments
Closed

Color codes garble output in PowerShell #6

corneliusweig opened this issue Feb 28, 2019 · 2 comments
Assignees

Comments

@corneliusweig
Copy link
Owner

Expected behavior:
Output on PowerShell terminals is simply monochrome and well-formatted.

Actual behavior:
Unix terminal color codes are printed in PowerShell, thus making the output unreadable.

Relates to #5

@itowlson
Copy link
Contributor

itowlson commented Mar 1, 2019

This occurs because the Go terminal.IsTerminal function returns true for PowerShell terminals (see implementation at https://go.googlesource.com/crypto/+/refs/heads/master/ssh/terminal/util_windows.go). Which is fair enough because the PowerShell console is a terminal, just not one that consistently supports VT100 sequences.

Looking at https://docs.microsoft.com/en-us/windows/console/getconsolemode, I think what we're really interested in is whether the current console mode includes the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag. Obviously Go doesn't surface this from its libraries, but we could try replacing the IsTerminal call with a custom SupportsEscapeSequences function which would return IsTerminal on Unix but would additionally check the console mode on Windows. This gives a better user experience but is more invasive and risky (ripping out a stdlib function and replacing it with a custom one).

Alternatively, we could just turn colouring off entirely on Windows, i.e. the check for colouring would not be IsTerminal but IsTerminal && IsUnix.

Let me know your preference @corneliusweig - I have to admit I'm inclined to take the second option for now as it will be simpler and will still achieve the immediate goal of 'simple and well formatted.'

@corneliusweig
Copy link
Owner Author

corneliusweig commented Mar 1, 2019

Wow, thanks for your thorough investigation! You seem to be a PowerShell wizard :)

I had thoughts into the same direction, to completely turn off colors on windows. Alas, that would also turn off colors on terminals that do support colors, like the widespread git-shell. However, your idea opens up a far superior alternative. I think we should definitely try this one out -- this tool is not production critical, so it's a good test balloon. Other projects could benefit from this solution too, if it works reliably!

So let's try your idea about SupportsEscapeSequences.

corneliusweig pushed a commit that referenced this issue Mar 2, 2019
Usually, logrus does this when printing the first log message. Since we usually don't log anything before printing, this setup work needs to be done manually. The implementation is very much based on that from logrus.

Fixes #6
@corneliusweig corneliusweig self-assigned this Mar 2, 2019
corneliusweig pushed a commit that referenced this issue Mar 3, 2019
Usually, logrus does this when printing the first log message. Since we usually don't log anything before printing, this setup work needs to be done manually. The implementation is very much based on that from logrus.

Fixes #6
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

2 participants