jdeploy icon indicating copy to clipboard operation
jdeploy copied to clipboard

Colors support for CLI output

Open andrii-bodnar opened this issue 5 years ago • 6 comments

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:

Screenshot from 2020-12-11 17-43-48

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

Screenshot from 2020-12-11 17-42-38


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?

andrii-bodnar avatar Dec 11 '20 15:12 andrii-bodnar

@shannah just a friendly reminder :slightly_smiling_face:

andrii-bodnar avatar Dec 23 '20 11:12 andrii-bodnar

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

mddanishansari avatar Sep 17 '21 06:09 mddanishansari

@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 avatar Jul 13 '22 12:07 ravn

@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 avatar Jul 13 '22 12:07 andrii-bodnar

@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

  1. ANSI is enabled when system property os.name starts with "Windows" and JAnsi Console is installed.

or

  1. 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 avatar Jul 13 '22 16:07 ravn

@ravn thanks a lot for the detailed investigation!

andrii-bodnar avatar Jul 14 '22 06:07 andrii-bodnar