Skip to content

Instantly share code, notes, and snippets.

@edwardhotchkiss
Created December 22, 2011 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardhotchkiss/1511616 to your computer and use it in GitHub Desktop.
Save edwardhotchkiss/1511616 to your computer and use it in GitHub Desktop.
NodeJS CLI Terminal Colors
/*!
__defineGetter__(<ANSI supported color>, fn
http://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes
*/
['magenta','yellow','green','blue','cyan','red'].forEach(function(color) {
var colorized = '\u001b[#m';
String.prototype.__defineGetter__(color, function(){
var options = {
cyan : 6,
magenta : 5,
blue : 4,
yellow : 3,
green : 2,
red : 1,
reset : 0
};
return colorized.replace(/#/, '3'+options[color])+this+colorized.replace(/#/, 0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment