Skip to content

Instantly share code, notes, and snippets.

@russellbeattie
Created March 18, 2013 02:54
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 russellbeattie/5184693 to your computer and use it in GitHub Desktop.
Save russellbeattie/5184693 to your computer and use it in GitHub Desktop.
Function to color the output in Node.js console.log() . I didn't realize until after I wrote this that utils.inspect sorta does the same thing.
function colorOutput(text, color){
color = color.toLowerCase();
var colors = {
'black':'0;30',
'dgray':'1;30',
'lgray':'0;37',
'blue':'0;34',
'lblue':'1;34',
'green':'0;32',
'lreen':'1;32',
'cyan':'0;36',
'lcyan':'1;36',
'red':'0;31',
'lred':'1;31',
'purple':'0;35',
'lpurple':'1;35',
'brown':'0;33',
'yellow':'1;33',
'white':'1;37'
}
if(colors[color]){
text = '\033[0' + colors[color] + 'm' + text + '\033[00m';
}
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment