由于眼睛的问题,我不得不将控制台背景色改为白色,但字体是灰色的,它使消息无法阅读。我怎样才能改变呢?


当前回答

如果你想改变颜色直接自己没有模块尝试

console.log('\x1b[36m', 'sometext' ,'\x1b[0m');

先\x1b[36m改变颜色为36,然后回到终端颜色0。

下面是ANSI颜色代码列表

其他回答

If you are using Windows CMD then go to the terminal Properties/Colors (CMD top left) and then redefine the RGB value of the offensive color. In my case I believe it's the fifth color square from the left, which I changed to (222,222,222). It does not matter if the currently selected radio button shows Screen Text or Screen Background as you just redefine that specific "system" color. Once you changed the color don't forget to select back the preferred color for the background or text before clicking OK.

更改后,所有来自Node(在我的情况下是Ember)的红色消息都清晰可见。

这适用于(我所知道的)Node控制台。

该包是快捷方式,您可以使用此命令安装它。 Const short = require('@testgrandma/shortcuts');

您可以执行两个命令来更改颜色。它是RGB颜色和Hex颜色short.colorRGB(r,g,b);

short.colorhex(十六进制);

你可以执行console.log(short.colorhex('d50000') + 'This is red!');

包裹可以在这里找到。

https://www.npmjs.com/package/@testgrandma/shortcuts

在Node.js中有多个可用于格式化控制台文本的包。最流行的有:

粉笔, cli-color - 颜色- >编辑:颜色不再推荐,因为它有拒绝服务漏洞 详情见:https://snyk.io/blog/open-source-npm-packages-colors-faker/

用法:

粉笔:

const chalk = require('chalk');
console.log(chalk.red('Text in red'));

CLI-COLOR:

const clc = require('cli-color');
console.log(clc.red('Text in red'));

在ubuntu中,你可以简单地使用颜色代码:

var sys = require('sys');
process.stdout.write("x1B[31m" + your_message_in_red + "\x1B[0m\r\n");

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"
FgGray: "\x1b[90m"

BgBlack: "\x1b[40m"
BgRed: "\x1b[41m"
BgGreen: "\x1b[42m"
BgYellow: "\x1b[43m"
BgBlue: "\x1b[44m"
BgMagenta: "\x1b[45m"
BgCyan: "\x1b[46m"
BgWhite: "\x1b[47m"
FgGray: "\x1b[100m"

例如,如果你想有一个昏暗的红色文本和蓝色背景,你可以在Javascript中这样做:

console.log("\x1b[2m", "\x1b[31m", "\x1b[44m", "Sample Text", "\x1b[0m");

颜色和效果的顺序似乎不是那么重要,但总是记得在最后重置颜色和效果。