3

I have added Git Bash to Windows Terminal as explained in Adding Git-Bash to the new Windows Terminal. My profile looks as follows:

{
    "guid": "{00000000-0000-0000-ba54-000000000002}",
    "commandline": "%PROGRAMFILES%/git/usr/bin/bash.exe -i -l",
    "icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico",
    "name": "Git Bash",
    "startingDirectory": "%USERPROFILE%",
}

I have a Picocli application that has colored output for the help message. When I invoke the help message in Git Bash in Windows Terminal it prints the ANSI color codes instead of coloring the text. To demonstrate this behavior I am using the example application of the Picocli docs:

ansi color codes not rendered in git bash in windows terminal

When I run the same command on Git Bash's terminal the colors are rendered properly:

correct color output in windows git bash terminal

Question

How can I get Git Bash in Windows Terminal to render ANSI colors in a Picocli application?

Additional information

As shown on the below image, proper text coloring in Git Bash in Windows Terminal can happen (I demonstrate this with Robot Framework, which doesn't use Picocli), so my issue is specific to Picocli.

coloring in git bash in windows terminal

HerCerM
  • 145
  • 2
  • 9
  • 1
    I just ran across this problem, too, and the solution was to use ANSICON. You don't need to install anything, just download the binaries and update your terminal launch to command to run ANSICON first, then GitBash, see https://github.com/symfony/cli/issues/181#issuecomment-579617318 – Chris Haas Sep 01 '21 at 16:23
  • @ChrisHaas that url has gone – Damian Green Apr 04 '23 at 18:21
  • 1
    @DamianGreen, since that posting I've switched to WSL exclusively, so I don't remember much, but maybe this post will be helpful: https://cjhaas.com/2021/09/01/windows-terminal-gitbash-colors/ – Chris Haas Apr 04 '23 at 18:24

1 Answers1

1

For showing ansi colors on Windows, I strongly recommend that applications use the Jansi library in combination with picocli.

Unless the specific software you’re using (e.g. java) enables ANSI processing by calling the SetConsoleMode API with the ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x0400) flag (java doesn’t), you won’t see colors or get ANSI processing for that application.

Jansi solves that issue.

For more details see: https://picocli.info/#_windows

Remko Popma
  • 35,130
  • 11
  • 92
  • 114