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

Windows Command Line and Powershell display ANSI escape codes instead of expected formatting #62

Closed
imartinezortiz opened this issue Nov 11, 2021 · 8 comments

Comments

@imartinezortiz
Copy link

Describe the bug

Hi, I've setup a simple maven project with your library to test the example code included in the README.md of the project, but unfortunately running the application does not show the text with colors and other attributes but the plain escape sequences. Trying to figure it out the problem, I also tested https://github.com/dialex/JColor-Sandbox with the same result.

Seems that during the migration process from JCDP to JColor you removed too much code, in particular the code included in baa3b95 that actually uses JNA to enable the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag.

Adding the enableWindows10AnsiSupport() method from the commit and the OS versions checks from that commit into the JColor-Sanbox project make it to work ok again.

Also, the pom.xml has a JNA as a compile time dependency but I can't find where it is used. Besides, xstream dependency is neither used, did I miss something ?

I suggest to at least add a section to the README.md with the boilerplate code required to activate the feature.

PS: congrats for your project

To Reproduce

  1. In a Win 10 clean machine setup create / compile https://github.com/dialex/JColor-Sandbox.
  2. Run the generated jar file in a Windows CMD terminal

Expected behavior
Show colored output of the application.

Screenshots
N / A

Environment

  • OS: Windows 10 21H1 (19043.1348)
  • Version 5.0.0, 5.0.2
@imartinezortiz
Copy link
Author

imartinezortiz commented Nov 11, 2021

Hi again, sorry that I didn't performed an exhaustive search in the closed issues. I can confirm that #54 (comment) solve does not solve the issue in some cases. I tested:

  • Windows CMD: WIN+R cmd.exe (does not work) 🔴
  • Windows Powershell: WIN+R powershell.exe (does not work) 🔴
  • Windows Terminal CMD: Windows Terminal > Open a cmd tab (does work) 🟢
  • Windows Terminal Powershell: Windows Terminal > Open Powershell tab (does work) 🟢

I have to declare that I just installed Windows Terminal out of curiosity and following your conversation at PowerShell/PowerShell#11449

Still, I suggest to document both options and provide a code snippet in the README.md so people can enable in the program itself. Some times you do not have permissions to change the registry (for example at School / University labs).

@dialex
Copy link
Owner

dialex commented Nov 11, 2021

Hola Ivan, and thank you for bringing this to my attention (and all the debugging you did!)

Which version of Powershell did you use, when JColor didn't work?

@imartinezortiz
Copy link
Author

imartinezortiz commented Nov 12, 2021

Olá Diogo, I tried the one that is by default installed in my laptop (windows 10 circa 2018) and seems to be Powershell 5.1.19041.1320. I get that version number when I run it directly (powershell.exe) o through Windows Terminal.
Just downloaded PS 7.2 (zip file) and run again the example project and same result. Without modifying the code shows the plain escape codes, adding the code to enable the flag run ok.
I'm guessing, but seems that key point is the running process through "Windows Terminal" (the new application that you have to install though Microsoft Store)

@dialex
Copy link
Owner

dialex commented Nov 12, 2021

Oh no, PS 7.2 didn't work?! Well 💩, I was not expecting that. I was able to reproduce it too...

This SO answer summarises the problem/solution regarding ANSI escapes codes on Windows Command Line / Powershell. I (mis)understood that Powershell +6 had support for ANSI codes by default. Clearly that is not the case, as you just showed.

Workarounds (sorted by descending order of convenience)

Next steps

I will add a note about this problem and workarounds in the docs.

@imartinezortiz
Copy link
Author

Hi, regarding the SO comment, I tried to follow the regedit approach without success (tried both closing the session and rebooting), at least trying to run the example application through Windows CMD or powershell (in both cases without using Windows Terminal). Did you have success following the instructions ?

Regarding the approach I would, at least, document both solutions, maybe not including the source code in the distribution itself, but at least in a sample project like JColor-Sandbox and referenced it from the README.md. My reasoning about documenting enableWindows10AnsiSupport() is due to I was trying to prepare a project template for my students that usually use both the university lab and their own computers at home, and I need something portable enough.

dialex added a commit that referenced this issue Nov 12, 2021
@dialex
Copy link
Owner

dialex commented Nov 12, 2021

I added a new section to the README to make this limitation explicit. Do you think it has enough info? If so, I will close the issue.

@dialex dialex changed the title Library and sample code does not work out of the box (ENABLE_VIRTUAL_TERMINAL_PROCESSING not enabled) Windows Command Line and Powershell display ANSI escape codes instead of expected formatting Nov 12, 2021
@dialex dialex self-assigned this Nov 12, 2021
@imartinezortiz
Copy link
Author

Hi @dialex I think that it has enough info. If you finally remove the JNA dependencies from the pom.xml, would be nice to make that clear that also in the comment / README.md.

@dialex
Copy link
Owner

dialex commented Nov 12, 2021

Cool! I will do that, but that will have to wait for a month, because I need to make a maven release from a machine with my credentials. But I will do that 😉 Thank you one more time for finding this bug! Ten un buen fin de semana

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

2 participants