Created
December 11, 2012 19:25
-
-
Save ValeriiVasin/4261265 to your computer and use it in GitHub Desktop.
Colorized output in nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var color, i; | |
// Notice: octal literals are not allowed in strict mode. | |
function colorize(color, output) { | |
return ['\033[', color, 'm', output, '\033[0m'].join(''); | |
} | |
for (i = 0; i < 100; i += 1) { | |
color = Math.random() > 0.9 ? 91 : 92; // 91 - red, 92 - green | |
process.stdout.write( colorize(color, '●') ); | |
} | |
process.stdout.write('\n'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For use in strict mode, instead of using the
\033
escape mode,\x1b
can be used:Source: https://gist.github.com/raghav4/48716264a0f426cf95e4342c21ada8e7