How to send control char using strict mode in javascript? - Stack Overflow

"use strict";var debug = function( m ) { console.log(' 33[32mdebug -33[39m:'

"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
Add a ment  | 

2 Answers 2

Reset to default 9

Use \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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745565715a4633381.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信