picocli: ColorScheme not working

picocli: 4.5.1

When exception is in Callable then from cli I should expect massage to be color red, but is not(powershell, gitbash)

My code:

static IExecutionExceptionHandler errorHandler = (Exception ex, CommandLine cmdL, ParseResult pr) -> {
        cmdL.getErr().println(cmdL.getColorScheme().errorText(ex.getMessage())); 
        return cmdL.getCommandSpec().exitCodeOnExecutionException();
};

public static void main( String[] args ) {
       ColorScheme colorScheme = createColorScheme();
       CommandLine commands = new CommandLine(new TopLavelCommands()).setColorScheme(colorScheme).setExecutionExceptionHandler(errorHandler);
        System.exit(commands ).execute(args);
}

private static ColorScheme createColorScheme() {
        return new ColorScheme.Builder()
                .commands(CommandLine.Help.Ansi.Style.bold, CommandLine.Help.Ansi.Style.underline) // combine multiple styles
                .options(CommandLine.Help.Ansi.Style.fg_yellow) // yellow foreground color
                .parameters(CommandLine.Help.Ansi.Style.fg_yellow)
                .optionParams(CommandLine.Help.Ansi.Style.italic)
                .errors(CommandLine.Help.Ansi.Style.fg_red, CommandLine.Help.Ansi.Style.bold)
                .stackTraces(CommandLine.Help.Ansi.Style.italic)
                .build();
}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 26 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Great! Please star ⭐ picocli on GitHub if you like the project! 😉

I have started the release for picocli 4.5.2, which contains the fix for MSYS2. So, from 4.5.2, gitbash should automatically show colors.

I don’t have a solution for Powershell… This may be a Powershell issue (looking at #849).

Thank you!

I see what the cause is: the TERM environment variable has value Cygwin and this is not recognized by picocli. I will fix this soon.

Can you provide details on the terminal software name and version?

@sysmat Are colors showing correctly when you execute <yourcmd> --help in those shells?

To help troubleshoot this issue, can you run again with system property -Dpicocli.trace=DEBUG on both shells, and copy-paste the output here?

The powershell problem may be related to this issue. (I have not heard any reports of problems with ANSI colors in gitbash until now.)