spring-bootterminal-color

How to restore terminal color to default after spring boot banner has printed


Spring boot offers a configurable banner via banner.txt that supports color, eg

${AnsiColor.RED}
  __  __         ____          _   ____                              
 |  \/  |_   _  |  _ \ ___  __| | | __ )  __ _ _ __  _ __   ___ _ __ 
 | |\/| | | | | | |_) / _ \/ _` | |  _ \ / _` | '_ \| '_ \ / _ \ '__|
 | |  | | |_| | |  _ <  __/ (_| | | |_) | (_| | | | | | | |  __/ |   
 |_|  |_|\__, | |_| \_\___|\__,_| |____/ \__,_|_| |_|_| |_|\___|_|   
         |___/                                                       
${AnsiColor.BRIGHT_WHITE}

Unfortunately, the final color of the banner sets the color for all output that follows from the spring boot app. The final color BRIGHT_WHITE is OK for the default linux background of BLACK, but I also run my app in the intellij console, which has a white background, so I can't see any output after the banner.

After the banner has printed to stdout, how do I restore terminal foreground and background color to what it was before the banner was printed?


Setting the background color of my Intellij terminal window to BLACK is not a solution, because that requires a local customization of an IDE to produce normal/expected behaviour, and one that other team members may not like or want. It would be a surprise to run the app locally with Intellij's default settings and wonder why the app is not producing any output.

Also, the same goes for the linux terminal, which may not have default color settings - again terminal colors are a personal choice, and should never be an operational requirement.


Solution

  • Try ${AnsiColor.DEFAULT}. I have not tried this but found a few examples which start the banner with a custom color and end it with default. For instance here, here, here and here.