Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

23 Commits

Repository files navigation

TERMplates

Download

TERMplates is a small wrapper around mustache.java which adds support for ANSI escape codes to render colors and text decorations.

Features

  • Colors Apply foreground and background colors.
  • Text Decorations Underline and bolden text.
  • TTY detection Ignore ANSI escape codes when not started from an interactive commandline.

Installation

Maven

<repositories>
<repository>
<id>bintray</id>
<url>http://dl.bintray.com/helpermethod/maven</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.helpermethod</groupId>
<artifactId>termplates</artifactId>
<version>0.1.0</version>
</dependency>

Gradle

repositories {
maven {
url "https://dl.bintray.com/helpermethod/maven"
}
}
compile 'com.github.helpermethod:termplates:0.1.0'

Usage

The static renderInline method takes a Mustache template of type String and a model of type Map or Object and returns the rendered template as a String.

varmodel = newMap.of("name","TERMplates");
System.out.println(Termplates.renderInline("Hello {{name}}!", model));

Colors can be accessed by using the {{term}} namespace.

System.out.println(Termplates.renderInline("Hello {{#term.red}}{{name}}{{/term.red}}", Map.of("name", "TERMplates")));

Colors and text decorations can be combined by nesting them (for a full list of supported escape sequences, see ANSI Escape Codes. ).

System.out.println(Termplates.renderInline("Hello {{#term.bold}}{{#term.red}}{{name}}{{/term.red}}{{term.bold}}", Map.of("name", "TERMplates")));

For rendering more complex templates, create a file ending on .mustache under src/main/resources/templates, e.g. movies.mustache.

{{#term.underline}}MOVIES{{/term.underline}}{{! iterates over the `movies` array and renders each element on its own line }}{{#movies}}{{.}}{{/movies}}

Use the static renderFile method to render the file containing the method.

// note that you reference the file only by its prefix, i.e. "movies", not "movies.mustache"System.out.println(renderFile("movies", Map.of("movies", List.of("Evil Dead", "Evil Dead 2", "Army Of Darkness"))));

ANSI Escape Codes

Foreground Colors

ColorFunction
blackterm.black
redterm.red
greenterm.green
yellowterm.yellow
blueterm.magenta
magentaterm.magenta
cyanterm.cyan
whiteterm.white

Text Decorations

DecorationFunction
boldterm.bold
underlineterm.underline
reverseterm.reverse

About

Mustache Templates for the Commandline

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages