chalkbars

Template based terminal coloring based on Chalk and Handlebars.

View on GitHub

Introduction

Package Version Dependency Status Build Status Coverage Status

Template based terminal coloring based on Chalk and Handlebars.

http://sw.cowtech.it/chalkbars

Usage

Chalkbars allows an easier use of chalk on the console taking advantage of the awesome Handlebars templating engine.

The use is really easy:

var chalkbars = require("chalkbars").format;
console.log(chalkbars("{{#C red}}This is in red{{/C}} and this is not."));

Supported implementations.

Chalkbars supports and has been tested on NodeJS 5.0+.

Chalkbars Handlebars helpers

C

This is the main template. It accepts one or more styles, concatenated by any character except letters, numbers and "#".

Even thought quotes are optional, is advised to always provide them for clarity.

This template will replace text inside with the styles provided.

It supports nesting.

Examples:

console.log(chalkbars("{{#C red}}This is in red except for {{#C green}}this{{/C}} and it supports restoring.{{/C}}"));
console.log(chalkbars("{{#C red.bgYellow}}This is in red with a yellow background.{{/C}}"));
console.log(chalkbars("{{#C red$bgYellow}}Same as above.{{/C}}"));

Supported styles are:

All unrecognized styles are ignored.

B

Outputs a header with a word between brackets.

It does not support nesting and does not support any embedded content.

It accepts one or two arguments. The first argument is the word to print, the second argument is the style. If the latter is omitted, the first word is also used as a style. Again, quoting is optional but advised.

Examples:

console.log(chalkbars("{{B info}} On the left you see a white 'INFO' word inside blue brackets"));
console.log(chalkbars("{{B \"info\" \"red\"}} On the left you see a red 'INFO' word inside blue brackets"));
console.log(chalkbars("{{B info red}} Omitting quotes might lead to unwanted behavior"));
console.log(chalkbars("{{B \"what\" \"red.bgYellow\"}} On the left you see a red on yellow background 'WHAT' word inside blue brackets"));

Shortcuts

The following shortcut helpers are also defined:

E

Outputs a footer with a word between brackets

It behaves like B but it makes sure the message is printed to the right of the screen.

console.log(chalkbars("On the right you see a white 'INFO' word inside blue brackets {{E info}}"));
console.log(chalkbars("On the right you see a red 'INFO' word inside blue brackets {{E \"info\" \"red\"}}"));
console.log(chalkbars("Omitting quotes might lead to unwanted behavior {{E info red}}"));
console.log(chalkbars("On the right you see a red on yellow background 'WHAT' word inside blue brackets {{B \"what\" \"red.bgYellow\"}}"));

Shortcuts

The following shortcut helpers are also defined:

Configuring Chalkbars

chalkbars.configuration.silent

Whether to ignore exceptions when compiling a Handlebars template fails.

If set to false a compilation failure will raise an exception.

The default value is true.

chalkbars.configuration.openingBracket

The default template for the opening bracket in the B and E templates.

The default value is {{#C bracket}}[{{/C}}.

chalkbars.configuration.closingBracket

The default template for the closing bracket in the B and E templates.

The default value is {{#C bracket}}]{{/C}}.

chalkbars.configuration.styles

The list of valid chalk styles for the C, B and E templates.

Do not modify this directly but use chalkbars.style instead.

API Documentation

The API documentation can be found here.

Contributing to chalkbars

Copyright

Copyright (C) 2015 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!