question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

banner.txt ansi color code not working in Windows 10 console

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
wzgycommented, Jul 14, 2019

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

1reaction
maurocapcommented, May 2, 2017

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use ANSI colors in the terminal - Windows CMD - SS64.com
Specify the color codes in a batch file by ECHOing the foreground and/or background color codes (from the following table) followed by the...
Read more >
Text art/Banner Not Appearing In cmd Prompt (Unicode/ASCII)
I figured it out. You need to enable "Use Legacy Console". Once you do that and restart the console the FreeMono font is...
Read more >
Support for colors in console output : IDEA-69880 - YouTrack
My ANSI color codes in my LogBack configuration do work in Eclipse console, but not in IDEA. :-( This happens even having installed...
Read more >
Spring Boot - Enabling Color Coded Output - LogicBig
Spring boot can display ANSI color coded output if the target terminal supports it. We need to set spring.output.ansi.enabled property.
Read more >
Spring Boot Banner - Complete Guide | SpringHow
To mark a text with yellow, wrap the content between ${AnsiColor.YELLOW} and ${AnsiColor.DEFAULT} . For background and text styles, the concept is the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found