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

3
  • 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 github.com/symfony/cli/issues/181#issuecomment-579617318 Commented Sep 1, 2021 at 16:23
  • @ChrisHaas that url has gone Commented Apr 4, 2023 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: cjhaas.com/2021/09/01/windows-terminal-gitbash-colors Commented Apr 4, 2023 at 18:24

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.