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

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.
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?
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.
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:
Thanks to everyone!
Thanks, we've considered Jansi support in the past but ruled it out due to some issues. See #2331 for background.
Windows 10 turns the Virtual Terminal Support OFF by default.
You have three options:
1.In registry key [HKEY_CURRENT_USERConsole], 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
@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.
Most helpful comment
Windows 10 turns the Virtual Terminal Support OFF by default.
You have three options:
1.In registry key [HKEY_CURRENT_USERConsole], 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