remkop/picocli

Improve ANSI heuristics: add support for ConEmu, ANSICON, NO_COLOR and CLICOLOR

Closed this issue · 15 comments

I'm running ConEmu on Windows 10, but Ansi colored mode won't be turned on when using Ansi.AUTO, while Ansi.ON works just fine. How can I remedy this?

Picocli uses a set of heuristics to determine whether to emit ANSI escape codes or not. These are mostly based on environment variables.

Let’s see what we can do to make this work on ConEmu.

Can you show a list of all environment variables on this system? I’m especially interested in the ConEmu variables, but other variables may be helpful if you could include them.

Looking at this list, especially the ConEmuANSI variable looks relevant. Is this environment variable defined and what is its value?

(See also:
https://conemu.github.io/en/AnsiEscapeCodes.html#Environment_variable )

The following prints out "enabled"

if "%ConEmuANSI%"=="ON"  echo Enabled
if "%ConEmuANSI%"=="OFF" echo Disabled

Can you show a list of all environment variables on this system? I’m especially interested in the ConEmu variables, but other variables may be helpful if you could include them.

Nothing out of the ordinary or ConEmu related. Only thing I noticed is:

ANSICON_HOME=C:\Users\Benny Bottema\Downloads\ansi185\x64
PATH=...%ANSICON_HOME%...

So it seems I have ANSI con installed in the past and later installed ConEmu. Following ConEmu's instructions furter:

$ set ansi
ANSICON=240x1000 (240x57)
ANSICON_DEF=7
ANSICON_HOME=C:\Users\Benny Bottema\Downloads\ansi185\x64

$ echo %ANSICON_VER%
170

Thank you for the information.
I’ve been doing some research.
Can you also give the value of the CLICOLOR and CLICOLOR_FORCE environment variables? These may be implemented as dynamic variables, so they won’t show up in the list printed by the set command. Instead please verify the value with:

echo %CLICOLOR%
echo %CLICOLOR_FORCE%

Thank you for the help!

Both empty.

Cool, thanks!
I’m thinking to make the following enhancements for picocli 3.9:
(In addition to the existing Ansi enablement logic)

  • disable Ansi when CLICOLOR == 0 or ConEmuANSI == OFF
  • enable Ansi when CLICOLOR == 1 or ConEmuANSI == ON or when ANSICON is defined
  • force Ansi ON when CLICOLOR_FORCE == 1

This should add ANSI color support for both ConEmu and AnsiCon, as well as add support for @jhasse ‘s https://bixense.com/clicolors/ proposal.

I’ll also add support for NO_COLOR: https://no-color.org/

man, what a mess. You'd think there would be a standard for everything terminal related by now. I mean, we've been only doing this since... I don't know, 50 years now.

I've pushed a commit to master to improve picocli's heuristics for determining whether it should emit ANSI escape codes or not.

This should address the issue on your system. Can you verify?

I'm still keeping the ticket open because I'm planning to add more unit tests for this.

Verified, it solves the problem in my situation 👍

Are you planning a release soon?

Thanks for the confirmation.

Yes, planning to do a release within about a week (see 3.9 milestone).
When exactly will depend a bit on how much more time it will take to improve the test coverage...

Hmm, what about the IntelliJ console? With AUTO it's turned off, but with ON it works fine. Is there a way of detecting ANSI support without manually configuring system variables?

No, not that I know of. The idea would be that all consoles which support colors but don't are a tty, set CLICOLOR_FORCE to 1.

I created this ticket for IntelliJ: https://youtrack.jetbrains.com/issue/IDEA-205699