Copyright 2017 Thomas Hellström.
https://github.com/thohell/librelaxed-ansicolors
This is a very simple and lightweight module that provides ansi escape codes suitable for output to text terminal/console. It only supports setting text attributes, foreground color and background color. The capabilities of the terminal limits which attributes and/or colors will render.
To use this module in a project:
npm install --save librelaxed-ansicolors
import { ansicolors } from 'librelaxed-ansicolors';
console.log(ansicolors.render(
{
attr: [ ansicolors.attr.underline, ansicolors.attr.bold ],
fg: ansicolors.color.white,
bg: ansicolors.color.rgb(0xff0000)
}) + 'Underlined, bold & white text on red background.');
import { ansicolors } from 'librelaxed-ansicolors';
const ansiFormat: ansicolors.ANSIColors_t = {
attr: [ attribute1, ..., attributeN ], // (Optional) attribute(s). See attributes below.
fg: colorspec, // (Optional) foreground color. See colorspec below.
bg: colorspec // (Optional) background color
};
const escapeString = ansicodes.render(
ansiFormat, // (Required) ansicolor format
false // (Optional) swap fg/bg colors in output
);
some.function.use(escapeString);
Below is a list of all settable attributes. Note that not all terminals will render all attributes!
ansicolors.attr.none
Reset all attributes
ansicolors.attr.bold
/colorspec.attr.dim
/colorspec.attr.noBoldOrDim
Bold text or Dim text on/off
ansicolors.attr.italic
/colorspec.attr.noItalic
Italics on/off
ansicolors.attr.underline
/colorspec.attr.noUnderline
Underlined text on/off
ansicolors.attr.blink
/colorspec.attr.noBlink
Binking text on/off
ansicolors.attr.invert
/colorspec.attr.noInvert
Inverted text (swap fg/bg) on/off
ansicolors.attr.invisible
/colorspec.attr.noInvisible
Invisible text on/off
ansicolors.attr.strikethrough
/colorspec.attr.noStrikethrough
Crossed out text on/off
ansicolors.attr.overline
/colorspec.attr.noOverline
Overlined text on/off
You can describe colors in three ways. Note that not all terminals will render all colors!
- By using names for simple colors (8/16 colors)
- By using index for indexed colors (88/256 colors)
- By using rgb for true color (24-bit colors)
ansicolors.color.normal
Use default color.
ansicolors.color.black
ansicolors.color.red
ansicolors.color.green
ansicolors.color.yellow
ansicolors.color.blue
ansicolors.color.magenta
ansicolors.color.cyan
ansicolors.color.lightGrey
ansicolors.color.darkGrey
ansicolors.color.lightRed
ansicolors.color.lightGreen
ansicolors.color.lightYellow
ansicolors.color.lightBlue
ansicolors.color.lightMagenta
ansicolors.color.lightCyan
ansicolors.color.white
ansicolor.color.index(i)
where i is index number 0-255
ansicolor.color.rgb([ r, g, b ])
where r, g & b are between 0-255
ansicolor.color.rgb(c)
where c is a 24 bit color between 0-0xffffff (0-16777215)
See LICENSE.md for information.