Search code examples
freemarker

FreeMarker ansi colors for console output


I'm using a Freemarker template the generate output for a cli tool.

Is it possible to add ANSI colors like \u001B[34m to the template?


Solution

  • I guess the question is about the \u001B (ESC). You can print that either by literarily including it in the template, or with ${'\x1B'}. Of course manually inserting escape sequences is still no much fun, so you might write some macros for it, for example:

    <#macro fg color>${'\x1B'}[${30 + color}m</#macro>
    
    <@fg 4 />This is blue. <@fg 2 />This is green.