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

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

Closed
bbottema opened this issue Dec 29, 2018 · 15 comments

Comments

@bbottema
Copy link
Contributor

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?

@remkop
Copy link
Owner

remkop commented Dec 29, 2018

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.

@remkop remkop added this to the 3.9 milestone Dec 29, 2018
@remkop
Copy link
Owner

remkop commented Dec 29, 2018

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 )

@bbottema
Copy link
Contributor Author

bbottema commented Dec 29, 2018

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

@remkop
Copy link
Owner

remkop commented Dec 29, 2018

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!

@bbottema
Copy link
Contributor Author

Both empty.

@remkop
Copy link
Owner

remkop commented Dec 29, 2018

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.

@remkop
Copy link
Owner

remkop commented Dec 29, 2018

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

@remkop
Copy link
Owner

remkop commented Dec 29, 2018

(Note to self: read http://tldp.org/HOWTO/Text-Terminal-HOWTO-16.html )

@bbottema
Copy link
Contributor Author

bbottema commented Dec 29, 2018

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.

remkop added a commit that referenced this issue Dec 30, 2018
…les to improve the ANSI heuristics. Documented the heuristics in the user manual.
@remkop
Copy link
Owner

remkop commented Dec 30, 2018

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.

@remkop remkop changed the title Ansi.AUTO not working on ConEmu windows 10 Improve ANSI heuristics: add support for ConEmu and ANSICON Dec 30, 2018
@remkop remkop changed the title Improve ANSI heuristics: add support for ConEmu and ANSICON Improve ANSI heuristics: add support for ConEmu, ANSICON, NO_COLOR and CLICOLOR Dec 30, 2018
@bbottema
Copy link
Contributor Author

bbottema commented Dec 30, 2018

Verified, it solves the problem in my situation 👍

Are you planning a release soon?

@remkop
Copy link
Owner

remkop commented Dec 30, 2018

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...

@bbottema
Copy link
Contributor Author

bbottema commented Jan 18, 2019

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?

@jhasse
Copy link

jhasse commented Jan 18, 2019

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.

@remkop
Copy link
Owner

remkop commented Jan 19, 2019

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

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

3 participants