Hello. banner.txt ansi colors doesn't work in Windows 10 console. Example:

banner.txt ${AnsiColor.RED}HELLO

The "HELLO" word should be red colored, but it doesn't in both cmd console and powershell console. But Window10 still supports ansi colors:

https://msdn.microsoft.com/en-us/library/windows/desktop/mt638032(v=vs.85).aspx

To test it I wrote a simple .bat file able to show colors in a standard cmd console:

test.bat @echo <ESC>[31mHELLO<ESC>[0m

Where <ESC> is the escape character (alt+027). This .bat shows the "HELLO" word red colored.

I tried to use the same escape sequence in banner.txt but it doesn't work too. It displays a broken character followed by [31m

Perhaps Spring Boot ansi constants are incorrect for a Window 10 environment?

Comment From: wilkinsona

I could be that we have not or even cannot detect that the Windows console supports ansi colors. Can you please try running your application with --spring.output.ansi.enabled=always and let us know if that helps.

Comment From: maurocap

--spring.output.ansi.enabled=always changed the output without adding any color. With this flag enabled the console output looks like the one I got when I manually edited banner.txt replacing ${AnsiColor.RED} with <ESC>[31m:

spring-boot-banner-spring output ansi enabled-true

Sorry for the image quality: our banner is quite big (112x13 characters). I cut and pasted only a part of it.

Well, this behaviour could also be a java output bug in Windows 10 environment. Actually I'm using jre1.8.0_131.

Comment From: wilkinsona

Thanks for trying the property.

Well, this behaviour could also be a java output bug in Windows 10 environment. Actually I'm using jre1.8.0_131.

Interesting. Can you get a plain (non Spring Boot) Java app to produce coloured output on Windows 10?

Comment From: maurocap

Interesting. Can you get a plain (non Spring Boot) Java app to produce coloured output on Windows 10?

Just did it: System.out.println("\u001B[31mHELLO"); shoud output a red string in the console, but it don't. It's definitely a java issue (or not an issue?) and not a Spring Boot one.

Sorry for the report.

Comment From: maurocap

I did a small research: it looks like pure java is not able to output ansi color the way a Windows console want them. I've found this project:

https://github.com/fusesource/jansi

Which expose two functions to enable/disable colored ansi output even on Windows. By using the library I was able to see colored output in a dos console:

public static void main(String[] args) {        
    AnsiConsole.systemInstall();
    System.out.println("\u001B[31mHELLO\u001B[37m");
    AnsiConsole.systemUninstall();
}

Anyway I was not able to see spring boot colored banner even with Jansi:

public static void main(String[] args) {
    AnsiConsole.systemInstall();
    SpringApplication.run(MyApplication.class, args);
    AnsiConsole.systemUninstall();
}

To summarize:

  1. the missing banner colors in Windows console is not a Spring Boot issue
  2. a Spring Boot very-low-priority feature could be to add Jansi or part of its functionalities to have colored consoles even in Windows environment

Thanks to everyone!

Comment From: philwebb

Thanks, we've considered Jansi support in the past but ruled it out due to some issues. See #2331 for background.

Comment From: wzgy

Windows 10 turns the Virtual Terminal Support OFF by default. You have three options: 1.In registry key [HKEY_CURRENT_USER\Console], create or set the VirtualTerminalLevel DWORD value to 1 2.Call to the SetConsoleMode() Windows API inside your program 3.Pipe output from external programs to Out-Host, like java -jar xxx.jar | Out-Host

https://stackoverflow.com/a/51681675/9480909

Comment From: xenoterracide

@wzgy do you know how to set that registry key with powershell? I've been trying but no luck. @philwebb any chance you'd consider adding jansi to managed dependencies and adding instructions? and/or adding the powershell registry instructions I just asked for to the docs.

Comment From: philwebb

@xenoterracide We'd probably not be too keen to add jansi as a managed dependency but documentation updates would certainly be worthwhile. I don't use Windows often enough to know what those instructions would look like, but if you get it working and have suggestions please open a new issue.