如何更改node.js的控制台字体颜色?
由于眼睛的问题,我不得不将控制台的背景颜色更改为白色,但是字体为灰色,这使消息不可读。我该如何更改?
回答:
在下面,您可以找到运行node.js应用程序时命令的文本颜色参考:
console.log('\x1b[36m%s\x1b[0m', 'I am cyan'); //cyanconsole.log('\x1b[33m%s\x1b[0m', stringToMakeYellow); //yellow
注意,%s
是在字符串(第二个参数)中注入的位置。\x1b[0m
重置终端颜色,以便在此之后不再继续成为所选颜色。
Reset = "\x1b[0m"Bright = "\x1b[1m"
Dim = "\x1b[2m"
Underscore = "\x1b[4m"
Blink = "\x1b[5m"
Reverse = "\x1b[7m"
Hidden = "\x1b[8m"
FgBlack = "\x1b[30m"
FgRed = "\x1b[31m"
FgGreen = "\x1b[32m"
FgYellow = "\x1b[33m"
FgBlue = "\x1b[34m"
FgMagenta = "\x1b[35m"
FgCyan = "\x1b[36m"
FgWhite = "\x1b[37m"
BgBlack = "\x1b[40m"
BgRed = "\x1b[41m"
BgGreen = "\x1b[42m"
BgYellow = "\x1b[43m"
BgBlue = "\x1b[44m"
BgMagenta = "\x1b[45m"
BgCyan = "\x1b[46m"
BgWhite = "\x1b[47m"
编辑:
例如,\x1b[31m
是一个 转义序列 ,它将被您的终端截获并指示其切换为红色。实际上,\x1b
是
的代码escape
。仅处理颜色和样式的转义序列也称为
并且已标准化,因此(应)在任何平台上都可以使用。
Wikipedia对不同终端如何显示颜色进行了很好的比较
https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
以上是 如何更改node.js的控制台字体颜色? 的全部内容, 来源链接: utcz.com/qa/408772.html