Template based terminal coloring made really easy.

View on GitHub


Release GoDoc Go Report Card %s %s License

Template based terminal coloring made really easy.



Tempera allows to add coloring to terminal in a really easy way.

Colorize strings

To colorize strings, simply use the Colorize function, passing a list of styles you want to apply. The list of supported color names correspondes to the keys of ANSICodes variable.

import "github.com/ShogunPanda/tempera"

inRed := tempera.Colorize("Colorized", "red")
inRedWithBlueBackground := tempera.Colorize("Colorized", "red bgBlue")

Colorize templates

To colorize a template using a tagged template syntax, simply use the ColorizeTemplate function.

import "github.com/ShogunPanda/tempera"

colored := tempera.ColorizeTemplate("{red}This is in red, {green underline}this in green underlined{-}, this in red again.")

The template recognizes styles between curly braces (use a double opening brace to escape them) and the token {-} as universal closing tag (which also restores the previous style).

The closing tag at the end of the string can be omitted, since tempera will append the global reset style (\x1b[0m) if any style was set.

If you want to discard styles to be restored, use the {reset} token.

Setting custom styles

If you want to define custom styles, use the AddCustomStyle function.

import "github.com/ShogunPanda/tempera"

tempera.AddCustomStyle("important", "red underline")
colored := tempera.ColorizeTemplate("This is in red, underlined.", "important")

256 and 16 millions colors support

tempera supports 256 ANSI codes and 16m RGB colors. Just give it a try:

import "github.com/ShogunPanda/tempera"

fgAnsi256 := tempera.Colorize("color me", "ansi:100")
bgAnsi256 := tempera.Colorize("color me", "bgANSI:3,4,5")

fgRgb := tempera.Colorize("color me", "rgb:255,0,0")
bgRgb := tempera.Colorize("color me", "bgRGB:0,255,0")

fgHex := tempera.Colorize("color me", "hex:#FF0000")
bgHex := tempera.Colorize("color me", "bgHEX:00FF00")

ANSI, RGB, and HEX can be used in style definitions and templates as well.

API Documentation

The API documentation can be found on GitHub.

Contributing to tempera


Copyright (C) 2018 and above Shogun (shogun@cowtech.it).

Licensed under the MIT license, which can be found at https://choosealicense.com/licenses/mit.

Your browser is obsolete. For the best browsing experience, update it for free by visiting BrowseHappy.
There is a shiny new version. Update now!
Made by a proud Italian!