Colors support for CLI output
Hi,
we are using the Jdeploy library for deploying and running the CLI tool written on Java.
Jdeploy is a great tool and everything is fine except for one little issue with colors.
If I run it as a regular Java application, colors are displayed correctly:

But if I run it as a command after installation via Jdeploy, colors are disappeared:

Tried to edit the jdeploy.js file and add --colors or --ansi to the command (cmd variable), but it doesn't work:
Exception in thread "main" java.lang.RuntimeException: org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: --colors
at ca.weblite.jdeploy.JDeploy.main(JDeploy.java:1174)
Caused by: org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: --colors
at org.apache.commons.cli.DefaultParser.handleUnknownToken(DefaultParser.java:347)
at org.apache.commons.cli.DefaultParser.handleLongOptionWithoutEqual(DefaultParser.java:394)
at org.apache.commons.cli.DefaultParser.handleLongOption(DefaultParser.java:371)
at org.apache.commons.cli.DefaultParser.handleToken(DefaultParser.java:239)
at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:120)
at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:76)
at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:60)
at ca.weblite.jdeploy.JDeploy.main(JDeploy.java:1145)
Exception in thread "main" java.lang.RuntimeException: org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: --ansi
at ca.weblite.jdeploy.JDeploy.main(JDeploy.java:1174)
Caused by: org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: --ansi
at org.apache.commons.cli.DefaultParser.handleUnknownToken(DefaultParser.java:347)
at org.apache.commons.cli.DefaultParser.handleLongOptionWithoutEqual(DefaultParser.java:394)
at org.apache.commons.cli.DefaultParser.handleLongOption(DefaultParser.java:371)
at org.apache.commons.cli.DefaultParser.handleToken(DefaultParser.java:239)
at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:120)
at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:76)
at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:60)
at ca.weblite.jdeploy.JDeploy.main(JDeploy.java:1145)
Is there any way to fix this issue?
@shannah just a friendly reminder :slightly_smiling_face:
I had similar issue, you case might be different but this worked for me. I had Jansi in my JAR file, removing jansi.jar from my executable JAR helped fix it for me.
Also try to update jdeploy's dependency shelljs version to 0.8.4
@andrii-bodnar It is your application that behaves differently, which is most likely due to the ANSI library you use not detecting correctly it is being launched from JDeploy.
What ANSI library do you use and how can you configure it to think it is ok in this situation? Environment variables are typically used for this.
@ravn I am using the Picocli tool for building CLI and it's using some ANSI library under the hood (PicocliRunner.java#L61), but I'm not sure what the library is used here.
@andrii-bodnar I had a quick look at the documentation and it looks like the "Enable ANSI or not?" mechanism is described at https://picocli.info/#_heuristics_for_enabling_ansi.
My guess would be that the two environments behave differently regarding either
- ANSI is enabled when system property os.name starts with "Windows" and JAnsi Console is installed.
or
- ANSI is disabled when Picocli guesses the program’s output stream is not connected to a terminal: when System.console() returns null. This check is omitted if picocli guesses the program is running in a Windows Cygwin, MSYS or MSYS2 environment: when system property os.name starts with "Windows" and either environment variable TERM contains cygwin or starts with xterm or environment variable OSTYPE is defined.
This will require you to experiment to find out exactly what is different, possibly in a debugger. Please update this issue with your findings.
@ravn thanks a lot for the detailed investigation!