1 # ansicolors [![build status](https://secure.travis-ci.org/thlorenz/ansicolors.png)](http://next.travis-ci.org/thlorenz/ansicolors)
3 Functions that surround a string with ansicolor codes so it prints in color.
5 In case you need styles, like `bold`, have a look at [ansistyles](https://github.com/thlorenz/ansistyles).
14 var colors = require('ansicolors');
17 var redHerring = colors.red('herring');
18 var blueMoon = colors.blue('moon');
19 var brighBlueMoon = colors.brightBlue('moon');
21 console.log(redHerring); // this will print 'herring' in red
22 console.log(blueMoon); // this 'moon' in blue
23 console.log(brightBlueMoon); // I think you got the idea
26 console.log(colors.bgYellow('printed on yellow background'));
27 console.log(colors.bgBrightBlue('printed on bright blue background'));
29 // mixing background and foreground colors
30 // below two lines have same result (order in which bg and fg are combined doesn't matter)
31 console.log(colors.bgYellow(colors.blue('printed on yellow background in blue')));
32 console.log(colors.blue(colors.bgYellow('printed on yellow background in blue')));
37 **ansicolors** allows you to access opening and closing escape sequences separately.
40 var colors = require('ansicolors');
42 function inspect(obj, depth) {
43 return require('util').inspect(obj, false, depth || 5, true);
46 console.log('open blue', inspect(colors.open.blue));
47 console.log('close bgBlack', inspect(colors.close.bgBlack));
49 // => open blue '\u001b[34m'
50 // close bgBlack '\u001b[49m'
55 Look at the [tests](https://github.com/thlorenz/ansicolors/blob/master/test/ansicolors.js) to see more examples and/or run them via:
57 npm explore ansicolors && npm test
61 **ansicolors** tries to meet simple use cases with a very simple API. However, if you need a more powerful ansi formatting tool,
62 I'd suggest to look at the [features](https://github.com/TooTallNate/ansi.js#features) of the [ansi module](https://github.com/TooTallNate/ansi.js).