I started writing more and more Node apps for the terminal and guess what? I liked them in color. So I decided I'd write a module to add colors to text for stuff that's printed to stdout
Yh I know there are other color packages....but this is just MINE!!
npm install --save @v3rse/chroma
To use, it copy it into your project and do:
var chroma = require('@v3rse/chroma'); // use chroma
// or
require('@v3rse/chroma')({ bindToCosole: true }); // bind chroma functionality to console.log directly
It can be used in the following ways:
chroma.<color>(string);
chroma.<format>(string);
chroma.<format>.<color|bgcolor>(string);
// or with { bindToCosole: true }
console.log.<color>(string);
console.log.<format>(string);
console.log.<format>.<color|bgcolor>(string);
console.log.<format>.<format>.<color|bgcolor>(string);
node test.js
Terminal code (ANSI/VT100) introduction
echo
to test these codes manually.0x1B
or 033
in octal form. This is written as \x1b
when using echo
.\x1b[2m
) which is followed by whatever text stream.echo "a\x1b[2mb\x1b[0m"
tput
as an intermediary to the terminal.terminfo
database.capability names
and parameters to do this.echo "a$(tput dim)b$(tput sgr0)"
30m
to 39m
40m
to 49m
0m
and tells the terminal where to stop the effects of the previous code.4m
and 24m
for unsetting.1m
3m
2m
chroma.underline.red("Hello Word");
(Thanks to @oddoye-david )