Package Exports
- trucolor
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (trucolor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Trucolor
A node module and CLI utility for using 24bit color SGR codes in modern terminals.
Install
Global version, for CLI use
npm install --global trucolor
Module, for programmatic use
npm install --save trucolor
CLI Usage
Synopsis:
trucolor [options] [name]: [operation...] color [operation...]
...[[name]: [operation...] color [operation...]]...
Options:
-h, --help Display this help.
-v, --version Return the current version. -vv Return name & version.
-V, --verbose Be verbose. -VV Be loquacious.
-m, --message Format message with SGR codes
-i, --in Output SGR color escape code.
-o, --out Output cancelling SGR color escape code.
-t, --type CLI styling flags output. [none | direct | fish]
-r, --rgb Output color as rgb(r, g, b)
-s, --swatch Output an isolated color swatch.
In it's simplest form, trucolor 'color'
, will take any of the color expressions listed below and transform it into a simple hexadecimal triplet string, i.e AA00BB
, ideal for passing into fish-shell's set_color
built-in, or providing the basis of further color processing.
It can return color values and set terminal colors for a wide range of color assignment declarations and manipulation functions, based internally on the color-convert
node module and less
. See the examples below.
When outputting SGR codes, colors will be shifted to the availalble 256 or ansi color palette if 24 bit color is unavailable or will be omitted in a monochromatic terminal to make usage across environments safe. The CLI command respects --color=16m
, --color=256
, --color
and --no-color
flags. It does not affect value based output, such as the default or --rgb
output, it only effects the --in
, --out
, --message
and --swatch
outputs.
The motivation for this is to allow more sophisticated graphic visualisation using in modern, xterm-compatible terminal emulators that have added 24 bit support.
Color definition
The color
can be defined in any of the following formats:
CSS Hexadecimal
[#]RRGGBB
or[#]RGB
whereR
,G
andB
are 0-F.RGB
rgb:R,G,B
orrgb(R,G,B)
whereR
,G
andB
are 0-255.
Spaces can be incuded in rgb(R, G, B) declarations but require quoting/escaping on the CLI.HSL (Hue Saturation Lightness)
hsl:H,S,L
whereH
is 0-360,S
0-100 andL
0-100HSV (Hue Saturation Value)
hsv:H,S,V
whereH
is 0-360,S
0-100 andV
0-100HSB (Hue Saturation Brightness) (just an alias for HSV)
hsb:H,S,B
whereH
is 0-360,S
0-100 andB
0-100HWB (Hue White Black)
hwb:H,W,B
whereH
is 0-360,W
0-100 andB
0-100
See HWB notation @csswgCSS named colors
Special formatters The following keywords modify the meaning or destination of the color, or provide enhanced foramtting. They only work when used with the command switches that actually output SGR codes, namely:
--message
,--swatch
,--in
and--out
. When used with the default command or with the--rgb
switch, they have no effect and the value of the base color (plus any processing) will be output.background: Set the background color, rather than the foreground.
normal: Set the color to the default foreground and background.
reset: Sets colors and special formatting back to the default.bold: Set the font to bold.
italic: Set the font to italic.
underline: Set underline.
dim: Set the colour to 50% opacity.
invert: Invert the foreground and background.
blink: Annoying as a note in Comic Sans, attached to a dancing, purple dinosaur with a talking paperclip.All of the above formatters need the correct code to end the range, either provided by using the
--out
switch, using thereset
keyword, or simply use the--message
option to automatically set the end range SGR code. Usingnormal
alone won't fully clear the formatting.
Color manipulation
A number of color operations
can be specified, either before or after the base color declaration.
light | dark : preset 20% darken/lighten.
saturate | sat | desaturate | desat | lighten | darken percent : basic operations.
spin degrees : hue shift.
mix | multiply | screen (named
| rgb()
| #hex
) : mix with color.
overlay | softlight | soft | hardlight | hard color : light with color.
difference | diff | exclusion | excl color : subtract color.
average | ave | negation | not color : blend with color.
contrast dark color [light color]
[threshold]
: calculate contrasting color.
See http://lesscss.org/functions/#color-operations for more details.
Multiple Inputs
trucolor
will output a list of color values if more than one base color is specified, allowing color assignment in a single block allowing easy ingest using read
. Each color will be output on it's own line, and named according to the input base color. The names can be overridden by providing a name:
before the base color.
> trucolor red yellow green purple
red FF0000
yellow FFFF00
green 008000
purple 800080
> trucolor Po: red LaaLaa: yellow Dipsy: green TinkyWinky: purple
Po FF0000
LaaLaa FFFF00
Dipsy 008000
TinkyWinky 800080
> trucolor hsl:120,100,50 apples: orange spin 180
hsl-120-100-50 00FF00
apples 005AFF
Custom Names:
Any color definition can be prefixed with a name:
and the result will be cached with that name, allowing it to be recalled by the same name later.
> trucolor bob: black lighten 50 saturate 50 spin 180
40BFBF
> trucolor --rgb bob:
rgb(64, 191, 191)
Supported and tested terminals include:
Obviously all this depends on your terminals support for the extended formatting. The latest iTerm2 builds and X's XTerm have full support for everything trucolor
can do, and anything that supports a terminal type of 'xterm-256color' will cover a fairly complete subset.
For example, Apple's Terminal.app doesn't have 24 bit color support nor does it have support for italics, but everything else works well.
- iTerm2 2.9 Beta (OS X)
- XTerm (^314 XQuartz 2.7.8)
Please let me know results in your terminal. http://github.com/MarkGriffiths/trucolor
Programmatic Usage
More to come here...
Simple generic palette
I use this to make sure help pages have consistent color between different modules.
var palette = require('trucolor').simplePalette();
var palette256 = require('trucolor').simplePalette({force: 'hundreds'});
var palette16 = require('trucolor').simplePalette({force: 'color'});
Without forcing, the palette will default to your terminal's color depth.
Bulk color creation
var trucolor = require('trucolor');
// the options object can be passed empty - the default output is 'sgr'
var palette = trucolor.bulk({ output: 'sgr|value|swatch' }, {
color_1: 'red lighten 10',
color_2: '#fe2316',
color_3: 'hsl(120,50,60)'
});
Chalk-ish behaviour
Trucolor also let's you style strings similar to Sindre Sorhus' Chalk, but allowing access to the full 256 and 24bit gamut.
var trucolor = require('trucolor');
var palette = trucolor.chalkish(trucolor.bulk({}, {
color_1: 'red lighten 10',
color_2: '#fe2316',
color_3: 'hsl(120,50,60)'
}));
console.log(palette.color_1("Style" + palette.color_2(' with ')) + 'functions')
The 'simple' palette can be set using:
var palette = require('trucolor').chalkishPalette();