最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论
"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.

发布评论

评论列表(0)

  1. 暂无评论