Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including termcolors with all npm packages installed. Try it out:

var termcolors = require("termcolors")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

termcolors v0.5.0

Convert color schemes to multiple terminal configs


Import and export between multiple terminal colour scheme formats

Many templates are sourced from the Base16-Builder.

Colors are handled using Colr.


npm install termcolors

Terminal Usage

Use the -i and -o flags to set the input and output formats. Pipe the input data into stdin.

Missing colors will be automatically replaced with the default colors.

Reading from one file and writing to another:

$ termcolors -i xresources -o json < ~/.Xresources > output.json

Reading from xrdb output, and writing to stdout:

$ xrdb -q | termcolors -i xresources -o text

JS API Usage

var fs = require('fs');
var termcolors = require('termcolors');

var xresources = fs.readFileSync('~/.Xresources', 'utf8');
var colors = termcolors.xresources.import(xresources);

var iterm = termcolors.iterm.export(colors);
fs.writeFile('~/config.itermcolors', iterm);

Supported Formats

Note: only a select few formats support importing.

Chrome Secure Shellchromeshell
Linux Consolelinux
Simple Terminalst
Plain Texttext
Sublime Text / Textmatetextmate
XFCE4 Terminalxfce

DIY Export

Templates use doT.js.

Check the templates folder for some examples.


termcolors.export(template, [transformer])

  • template (string)
  • transformer (function)

The transformer is an optional function that is passed the colors input into the template and can transform them for use in the template.

This is useful so that you don't have to use the tinycolor

Example Without Converter:

var template = 'body { background {{=c.background.hexString()}}; }'

var cssTemplate = termcolors.export(template);

Example With Converter:

var template = 'body { background: {{=c.background}}; }'

var toHex = function (colors) {
    return {
        background: colors.background.hexString();

var cssTemplate = termcolors.export(template, toHex);

Example With Lodash Mapping:

var _ = require('lodash');
var template = 'body { background: {{=c.background}}; }'

var toHex = _.partialRight(_.mapValues, function (color) {
    return color.hexString();

var cssTemplate = termcolors.export(template, toHex);
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free