由于眼睛的问题,我不得不将控制台背景色改为白色,但字体是灰色的,它使消息无法阅读。我怎样才能改变呢?
当前回答
这适用于(我所知道的)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
其他回答
另一种方法是使用一个简单的ANSI代码生成器。
您不需要安装软件包 不需要搜索颜色代码,只需点击按钮
GIF演示
你可以在https://console-colors.vercel.app/上使用它
公共存储库:https://github.com/alecshoppe/console-colors
paint-console
简单的可着色原木。支持检查对象和单行更新 这个包只是重新油漆控制台。
安装
npm install paint-console
使用
require('paint-console');
console.info('console.info();');
console.warn('console.warn();');
console.error('console.error();');
console.log('console.log();');
demo
Coolors
它非常适合使用或扩展。你可以简单地使用:
var coolors = require('coolors');
console.log(coolors('My cool console log', 'red'));
或者使用config:
var coolors = require('coolors');
console.log(coolors('My cool console log', {
text: 'yellow',
background: 'red',
bold: true,
underline: true,
inverse: true,
strikethrough: true
}));
延伸一下似乎很有趣:
var coolors = require('coolors');
function rainbowLog(msg){
var colorsText = coolors.availableStyles().text;
var rainbowColors = colorsText.splice(3);
var lengthRainbowColors = rainbowColors.length;
var msgInLetters = msg.split('');
var rainbowEndText = '';
var i = 0;
msgInLetters.forEach(function(letter){
if(letter != ' '){
if(i === lengthRainbowColors) i = 0;
rainbowEndText += coolors(letter, rainbowColors[i]);
i++;
}else{
rainbowEndText += ' ';
}
});
return rainbowEndText;
}
coolors.addPlugin('rainbow', rainbowLog);
console.log(coolorsExtended('This its a creative example extending core with a cool rainbown style', 'rainbown'));
视图Coolors模块
2017:
简单的方法,为消息添加时间颜色,你不需要改变你的代码,使用keep your console.log('msg')或console.err('error')
var clc = require("cli-color");
var mapping = {
log: clc.blue,
warn: clc.yellow,
error: clc.red
};
["log", "warn", "error"].forEach(function(method) {
var oldMethod = console[method].bind(console);
console[method] = function() {
oldMethod.apply(
console,
[mapping[method](new Date().toISOString())]
.concat(arguments)
);
};
});
node-colorify
提供功能打印文本的颜色,也做文本格式,如粗体,闪烁等。
推荐文章
- 对嵌套文件夹运行npm install的最好方法是什么?
- 节点Multer异常字段
- 很好的初学者教程socket.io?
- 如何在Visual c++中保持控制台窗口打开?
- CALL_AND_RETRY_LAST分配失败-进程内存不足
- 在Ubuntu上安装Node.js
- 使用express.js代理
- 如何在新的材质主题中改变背面箭头的颜色?
- Node -使用NODE_MODULE_VERSION 51根据不同的Node.js版本编译
- RabbitMQ / AMQP:单队列,同一消息的多个消费者?
- Node.js同步执行系统命令
- 我如何改变我的提示在zsh的颜色(不同于正常的文本)?
- 如何改变循环进度指示器的颜色
- 禁用包的postinstall脚本
- Node.js上的html解析器