如何更改 node.js 的控制台字体颜色? [英] How to change node.js's console font color?
问题描述
由于眼睛问题,我不得不将控制台背景颜色更改为白色,但字体是灰色的,这使得消息无法阅读.我该如何更改?
I had to change the console background color to white because of eye problems, but the font is gray colored and it makes the messages unreadable. How can I change it?
推荐答案
下面你可以找到运行 node.js 应用程序时文本到命令的颜色参考:
Below you can find colors reference of text to command when running node.js application:
console.log('x1b[36m%sx1b[0m', 'I am cyan'); //cyan
console.log('x1b[33m%sx1b[0m', stringToMakeYellow); //yellow
注意 %s
是注入字符串(第二个参数)的位置.x1b[0m
重置终端颜色,因此在此之后它不再是所选颜色.
Note %s
is where in the string (the second argument) gets injected. x1b[0m
resets the terminal color so it doesn't continue to be the chosen color anymore after this point.
颜色参考
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
的代码.仅处理颜色和样式的转义序列也称为 ANSI 转义码 并且是标准化的,因此它们(应该)适用于任何平台.
For example, x1b[31m
is an escape sequence that will be intercepted by your terminal and instructs it to switch to the red color. In fact, x1b
is the code for the non-printable control character escape
. Escape sequences dealing only with colors and styles are also known as ANSI escape code and are standardized, so therefore they (should) work on any platform.
维基百科对不同终端如何显示颜色进行了很好的比较https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
Wikipedia has a nice comparison of how different terminals display colors https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
这篇关于如何更改 node.js 的控制台字体颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!