"use strict";
var debug = function( m ) {
console.log(' \033[32mdebug -\033[39m:' + m );
}
The \033 is not going to fly with the strict mode any way around that beside taking off the strict mode?
"use strict";
var debug = function( m ) {
console.log(' \033[32mdebug -\033[39m:' + m );
}
The \033 is not going to fly with the strict mode any way around that beside taking off the strict mode?
Share Improve this question edited Apr 16, 2012 at 7:37 Andreas Wong 60.6k19 gold badges111 silver badges123 bronze badges asked Apr 16, 2012 at 7:26 AvengerMoJoAvengerMoJo 1186 bronze badges 4-
2
What exactly do you mean with
\033
? – KooiInc Commented Apr 16, 2012 at 7:45 - @AvengerMojo: What do you use to run the JavaScript? node? – Aaron Digulla Commented Apr 16, 2012 at 8:08
-
1
@KooiInc: \033 is escape. linux.die/man/4/console_codes
\033[32m
changes the foreground color. bashguru./2010/01/shell-colors-colorizing-shell-scripts.html – Aaron Digulla Commented Apr 16, 2012 at 8:09 - I'm sure there is a package which handles color codes nicely for you. Don't do it on your own. – ThiefMaster Commented Apr 16, 2012 at 8:11
2 Answers
Reset to default 9Use \u001b
instead. \0...
is an octal escape sequence which your JavaScript environment might not support.
An easy way to do this is to use the colorette package. Once you install the package with:
yarn add colorette
then you can do something like:
const { red, blue, bold } = require("colorette");
console.log(bold(blue("Engage!")));
Nice and simple.