acquerello

Template based terminal coloring made really easy.

View on GitHub

Introduction

%s%s%s%s

Template based terminal coloring made really easy.

http://sw.cowtech.it/acquerello

Usage

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

Colorize templates

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

import { colorize } from 'acquerello' 
 
console.log(colorize('{{red}}This is in red, {{green underline}}this in green underlined{{-}}, this in red again.')) 

The template recognizes styles between double curly braces and the token {{-}} as universal closing tag (which also restores the previous style).

Acquerello supports all colors codes recognized by ansi-style (and therefore by chalk).

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

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

Setting custom styles

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

import { colorize, addCustomStyle } from 'acquerello' 
 
addCustomStyle('important') 
console.log(colorize('{{important}}This is in red, underlined.{{-}}')) 

256 and 16 millions colors support

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

import { colorize } from 'acquerello' 
 
console.log(colorize('{{ansi:100}}color me{{-}}')) 
console.log(colorize('{{bgANSI:3,4,5}}color me{{-}}')) 
 
console.log(colorize('{{rgb:255,0,0}}color me{{-}}')) 
console.log(colorize('{{bgRGB:0,255,0}}color me{{-}}')) 
 
console.log(colorize('{{hex:#FF0000}}color me{{-}}')) 
console.log(colorize('{{bgHEX:00FF00}}color me{{-}}')) 

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

Colorize strings

To colorize strings, simply use the applyStyle, passing a list of styles you want to apply.

import { applyStyle } from 'acquerello' 
 
const inRed = applyStyle('Colorized', 'red') 
const inRedWithBlueBackground = applyStyle('Colorized', 'red bgBlue') 

ESM Only

This package only supports to be directly imported in a ESM context.

For informations on how to use it in a CommonJS context, please check this page.

Contributing to acquerello

Copyright

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

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

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!