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 codes are displayed instead of formatting text #11449

Closed
dialex opened this issue Dec 28, 2019 · 12 comments
Closed

Ansi codes are displayed instead of formatting text #11449

dialex opened this issue Dec 28, 2019 · 12 comments
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-External The issue is caused by external component(s).

Comments

@dialex
Copy link

dialex commented Dec 28, 2019

Steps to reproduce

git clone https://github.com/dialex/JcdpConsumer
mvn package
java -jar target/JCDP-Sandbox-0.0.0-jar-with-dependencies

Expected behavior

The output is colored (both font and background)

Actual behavior

The output is not colored, and shows Ansi codes

Context

This is how it looks on Windows PS6 vs Windows Terminal (maybe you can reach out to your fellow teammates and ask what they're doing differently):
Capture

I'm the maintainer of JCDP, a java lib to print formatted output on terminals. For that it uses standard Ansi codes. On Linux/Mac it always worked fine. On Windows, I had to depend on Jansi to convert those Ansi codes to something Windows friendly.

I read that Win10 now supports Ansi codes, so I removed the Jansi dependency (dialex/JColor#25) and tried to run the lib again. Sadly it didn't work on Win PS6... I'm not sure why. Is it because I need to enable the "Virtual Terminals" feature? Then why does it work out of the box for Win Terminal?

@dialex dialex added the Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a label Dec 28, 2019
@dialex dialex changed the title Ansi codes are displayed instead of color/formatting Ansi codes are displayed instead of formatting text Dec 28, 2019
@iSazonov
Copy link
Collaborator

iSazonov commented Dec 28, 2019

This is how it looks on Windows PS6 vs Windows Terminal
Then why does it work out of the box for Win Terminal?

I don't understand that you compare.
There are:

  • classic Windows console and new Windows Terminal
  • PS7 and Windows PowerShell

So we have 4 cases for comparison.
Please clarify that does not work for you.
And please use latest PowerShell 7 build for tests.

@dialex
Copy link
Author

dialex commented Dec 28, 2019

Sorry if I wasn't clear, that's on me. Windows has 4 diff command lines? 😵

Here's my problem: my lib claims that a dev can use it to format the text the send to a command line. Right now, it "just works" on Linux and macOS, so I don't need to issue any requirements to devs. So what are the requirements for it to work on Windows?

  • You must have Windows 10 Version 1511 or up
  • You must use XXXX cli
    • what goes here? PS6? PS7? Win Terminal?
    • what is the defacto cli for Windows devs, that also supports Ansi codes? I don't develop on Windows so I wouldn't know -- I trust your advice 🙏

Regarding PS6 vs PS7, I installed PS6 this month. The only reason I didn't go for PS7 was because at the time it was on "Preview". Is it safe/stable to switch? Again, I'll use whatever you advise me to.

@iSazonov
Copy link
Collaborator

I don't understand why Windows PowerShell is on right side of your screenshot.

@dialex
Copy link
Author

dialex commented Dec 28, 2019

I don't understand why Windows PowerShell is on right side of your screenshot.

What is it that you don't understand? Can you be more precise? On the right I have Windows Terminal, because I read somewhere that it was the "new and best" cli for Win. I don't know why Windows Terminal opens a PowerShell tab, your team mates might.

Did you read any of my previous questions? I'll try to be even more precise: What is the standard or officially recommended cli for (Java) developers on Windows 10?

@jhoneill
Copy link

jhoneill commented Dec 28, 2019

@dialex It isn't a powershell thing.
See https://devblogs.microsoft.com/commandline/new-experimental-console-features/

If your windows build is before 18298 the terminal doesn't support ansi codes. It doesn't matter if you run CMD, Windows PowerShell (5), PowerShell core (6) or the preview of 7, it's like the 1980s DOS without loading ANSI.SYS.

If you have a 18298 or later OR if you install the new Windows terminal, again CMD, Windows PowerShell or PowerShell core. will all display as you want. The new terminal will do it better and a lot faster.

It creates confusion when you say PowerShell core 6 in an old terminal doesn't do X but the older Windows PowerShell 5 in the new terminal does it.

Windows Command Line
As of Windows 10 build 18298, when you open the properties page of any Console window, you’ll notice an additional “Terminal” tab. Click on this tab and you’ll see several new settings for some experimental features we’re working on for future OS releases:

Important Note: These settings are “experimental”,

@iSazonov
Copy link
Collaborator

@dialex For classic Windows console you should continue to use Jansi. New Windows terminal supports escapes and you can remove Jansi.
PowerShell is a shell, not console, and don't implement console features like escapes. PowerShell has a formatting system which would broke your application output - in this case let us know.

@iSazonov iSazonov added the Resolution-External The issue is caused by external component(s). label Dec 29, 2019
@DHowett-MSFT
Copy link

DHowett-MSFT commented Dec 29, 2019

Hold up, what?

If your windows build is before 18298 the terminal doesn't support ansi codes. (@jhoneill)

For classic Windows Console you should...

This is entirely incorrect: the in-box standard windows console has supported ANSI (really, Xterm and VT100) since build 10240, which shipped almost four years ago.

The screenshot seems to show an application (java) not enabling ENABLE_VIRTUAL_TERMINAL_PROCESSING, a console mode that has existed since, again, build 10240.

Jansi probably enables that console mode, which is why it makes this work. God, I hope so: if it’s parsing VT sequences on its own it’s going to be terrible.

@DHowett-MSFT
Copy link

DHowett-MSFT commented Dec 29, 2019

I’d love to learn which piece of documentation told you that 18298 was the build that enabled ANSI, so that my team can go fix it.

EDIT: looks like that’s our blog, but somebody has misinterpreted the feature we were releasing. That isn’t “experimental support for ANSI”, that is “experimental support for a split color palette and configurable cursor types”

@jhoneill
Copy link

Hold up, what?

If your windows build is before 18298 the terminal doesn't support ansi codes. (@jhoneill)

This is entirely incorrect: the in-box standard windows console has supported ANSI (really, Xterm and VT100) since build 10240, which shipped almost four years ago.

EDIT: looks like that’s our blog, but somebody has misinterpreted the feature we were releasing. That isn’t “experimental support for ANSI”, that is “experimental support for a split color palette and configurable cursor types”

I'll put my hand up if I misread that... knowing it hasn't always worked but has worked for a decent length of time I went back to check and got the wrong info, if I'd thought a bit harder it should have dawned on me that the post was much too late a date. But I think I reposted an error rather than making a whole new one

@DHowett-MSFT
Copy link

@jhoneill my bad. Thanks for clarifying :) Yeah, it looks like a classic error-carried-forward.

@dialex
Copy link
Author

dialex commented Dec 30, 2019

The screenshot seems to show an application (java) not enabling ENABLE_VIRTUAL_TERMINAL_PROCESSING, a console mode that has existed since, again, build 10240.

That's my suspicion too @DHowett-MSFT (also thanks for joining the thread) 🙇
Since that feature is experimental for 4 years, I assumed that by now it was enabled by default.

I'll try to enable it and report back the results.

It creates confusion when you say PowerShell core 6 in an old terminal doesn't do X but the older Windows PowerShell 5 in the new terminal does it.

Yup, I'm confused as well. I tried PS5, PS6, cmd inside this new Windows Terminal and all showed color ✅However, when I run them individually (outside Win Terminal) they don't show color ❌

If all fails, I can just recommend my devs to use Windows Terminal. 🤷‍♂ Is that fair?

With so many Win clis, what is the officially recommended cli for developers on Windows 10?

<curiosity>

  • Is there something preventing the Windows team from enabling that feature by default, after this experimental time?
  • I checked and Jansi is not enabling that feature (Windows 10 supports ANSI natively fusesource/jansi#63), so they must do it some other way. I get it, they need to support Windows versions prior to 10.

</curiosity>

@dialex
Copy link
Author

dialex commented Dec 30, 2019

UPDATE: I enabled the feature, and now both PowerShell and Command Prompt display colors 😍

For reference, here's how to enable ENABLE_VIRTUAL_TERMINAL_PROCESSING using Java: dialex/JColor@baa3b95#diff-df3dc36270b358a02b972f5066b69a74R332

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-External The issue is caused by external component(s).
Projects
None yet
Development

No branches or pull requests

4 participants