如何改变node.js的控制台字体颜色? [英] How to change node.js's console font color?

查看:869
本文介绍了如何改变node.js的控制台字体颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不改变控制台背景颜色为白色,因为眼睛的问题,但字体是灰色的,它使消息不可读。

解决方案

Node.js中更改控制台字体颜色的几个模块最受欢迎的是:


  1. 粉笔 - https://github.com/ sindresorhus / 白垩

  2. 颜色 - https: /www.npmjs.org/package/ 颜色

  3. Cli-color - https://www.npmjs.org/package/ cli-color

白垩 用法:


npm install chalk




  var chalk = require ('粉笔'); 
console.log(chalk.red('Text in red'));

colors 用法:


npm安装颜色




  var colors = require('colors / safe'); //不改变字符串原型
console.log(colors.red('This String will Display RED'));

有几种颜色可供选择,以及文字格式,例如粗体 >修改 字符串原型,如果您更愿意使用原型,则需要使用 cli-color 粉笔



cli-color 用法:


npm install cli-color




  var clc = require('cli-color'); 
console.log(clc.red('Text in red')); cli-color 粉笔 需要更多打字但你得到类似的结果(到颜色),没有String原型添加。两者都支持各种颜色,格式(粗体/斜体等)和单元测试



选择您的选择。


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?

解决方案

There are a few modules for changing console font color in Node.js the most popular are:

  1. Chalk - https://github.com/sindresorhus/chalk
  2. Colors - https://www.npmjs.org/package/colors
  3. Cli-color - https://www.npmjs.org/package/cli-color

chalk usage:

npm install chalk

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

colors usage:

npm install colors

var colors = require('colors/safe'); // does not alter string prototype
console.log(colors.red('This String Will Display RED'));

There are a few colors to chose from as well as text formatting like Bold and Italic.

Many people have noted their disapproval at Colors altering the String prototype, if you prefer your prototypes left alone, you will want to use cli-color or chalk

cli-color usage:

npm install cli-color

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

Both cli-color and chalk require a bit more typing but you get similar results (to colors) without String prototype additions. Both support a good range of colors, formatting (bold/italics etc.) and have unit tests.

Take your pick.

这篇关于如何改变node.js的控制台字体颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆