admin管理员组文章数量:1431434
"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.
本文标签: How to send control char using strict mode in javascriptStack Overflow
版权声明:本文标题:How to send control char using strict mode in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745565714a2663747.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论