热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Node.jsnpmcolors

译自https:www.npmjs.compackagecolorscolorsgetcolorsinyournode.jsconsole在你的node.js控制台中获取颜色g

译自 https://www.npmjs.com/package/colors

colors

get colors in your node.js console

在你的 node.js 控制台中获取颜色

get color and style in your node.js console(在你的 node.js 控制台中获取颜色和风格)

这里写图片描述

安装


npm install colors


colors and styles(颜色和风格)


text colors(文本颜色)


  • black(黑色)
  • red(红色)
  • green(绿色)
  • yellow(黄色)
  • blue(蓝色)
  • magenta(品红/洋红/紫红)
  • cyan(青色)
  • white(白色)
  • gray(灰色)
  • grey(灰色)

background colors(背景颜色)


  • bgBlack(黑色)
  • bgRed(红色)
  • bgGreen(绿色)
  • bgYellow(黄色)
  • bgBlue(蓝色)
  • bgMagenta(品红/洋红/紫红)
  • bgCyan(青色)
  • bgWhite(白色)

styles(风格)


  • reset(重置)
  • bold(加粗)
  • dim(暗淡)【无效】
  • italic(斜体)【无效】
  • underline(下划线)【无效】
  • inverse(反色)【无效】
  • hidden(隐藏)【无效】
  • strikethrough(删除线)【无效】

extras(额外项)


  • rainbow(彩虹 - 红,黄,绿,蓝,紫红,)
  • zebra(有斑纹的)【无效】
  • america(美国国旗颜色 - 红,白,蓝)
  • trap(圈套 - 乱码)
  • random(随机颜色)

【无效】指的是在 Win10 下的测试结果

Usage(使用)


By popular demand, colors now ships with two types of usages!

应大众的要求,colors现在提供了两种使用方式!

The super nifty way

超级漂亮的方式

var colors = require('colors');console.log('hello'.green); // outputs green text
console.log('i like cake and pies'.underline.red) // outputs red underlined text
console.log('inverse the color'.inverse); // inverses the color
console.log('OMG Rainbows!'.rainbow); // rainbow
console.log('Run the trap'.trap); // Drops the bass(降低音)

在 Win10 下测试发现:underline、inverse、trap 均无效。

这里写图片描述

or a slightly less nifty way which doesn’t extend String.prototype

或者一个没有继承 String.prototype 的稍微不那么漂亮的方式

var colors = require('colors/safe');console.log(colors.green('hello')); // outputs green text
console.log(colors.red.underline('i like cake and pies')) // outputs red underlined text
console.log(colors.inverse('inverse the color')); // inverses the color
console.log(colors.rainbow('OMG Rainbows!')); // rainbow
console.log(colors.trap('Run the trap')); // Drops the bass

I prefer the first way. Some people seem to be afraid of extending String.prototype and prefer the second way.

我更喜欢第一种方式。相当多的人看起来害怕继承 String.prototype 并且更喜欢第二种方式。

If you are writing good code you will never have an issue with the first approach. If you really don’t want to touch String.prototype, the second usage will not touch String native object.

如果你的编码能力较好,那么对第一种方式将不会有任何问题。如果你实在不想接触 String.prototype,第二种使用方式将不会接触到字符串的对象。

Disabling Colors(禁用 colors)


To disable colors you can pass the following arguments in the command line to your application:

你可以在命令行中通过传递如下的参数到你的应用程序来禁用 colors:

node myapp.js -no-color

Console.log string substitution(控制台打印替换后的字符串)

var name = 'Marak';
console.log(colors.green('Hello %s'), name);
// outputs -> 'Hello Marak'

Custom themes(自定义主题)


Using standard API(使用标准的 API)

var colors = require('colors');colors.setTheme({silly: 'rainbow',input: 'grey',verbose: 'cyan',prompt: 'grey',info: 'green',data: 'grey',help: 'cyan',warn: 'yellow',debug: 'blue',error: 'red'
});// outputs red text
console.log("this is an error".error);// outputs yellow text
console.log("this is a warning".warn);

Using string safe API(使用字符串安全的 API)

var colors = require('colors/safe');// set single property
var error = colors.red;
error('this is red');// set theme
colors.setTheme({silly: 'rainbow',input: 'grey',verbose: 'cyan',prompt: 'grey',info: 'green',data: 'grey',help: 'cyan',warn: 'yellow',debug: 'blue',error: 'red'
});// outputs red text
console.log(colors.error("this is an error"));// outputs yellow text
console.log(colors.warn("this is a warning"));

You can also combine them:

你也可以将他们合并:

var colors = require('colors');colors.setTheme({custom: ['red', 'underline']
});console.log('test'.custom);

Protip: There is a secret undocumented style in colors. If you find the style you can summon him.

提示:colors 中有一个秘密的无明文规定的风格。如果你发现了这种风格,你就可以召唤它。

Protip 是新一代的 jQuery 提示插件。


推荐阅读
  • Node.js学习笔记(一)package.json及cnpm
    本文介绍了Node.js中包的概念,以及如何使用包来统一管理具有相互依赖关系的模块。同时还介绍了NPM(Node Package Manager)的基本介绍和使用方法,以及如何通过NPM下载第三方模块。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 网络请求模块选择——axios框架的基本使用和封装
    本文介绍了选择网络请求模块axios的原因,以及axios框架的基本使用和封装方法。包括发送并发请求的演示,全局配置的设置,创建axios实例的方法,拦截器的使用,以及如何封装和请求响应劫持等内容。 ... [详细]
  • 本文详细介绍了如何创建和使用VUE uni-app开发环境,包括通过HBuilderX可视化界面和通过vue-cli命令执行的方法。文章内容简单清晰,易于学习与理解。通过学习本文,读者可以深入了解VUE uni-app开发环境,并通过实践验证掌握具体的使用情况。编程笔记将为读者推送更多相关知识点的文章,欢迎关注! ... [详细]
  • Android日历提醒软件开源项目分享及使用教程
    本文介绍了一款名为Android日历提醒软件的开源项目,作者分享了该项目的代码和使用教程,并提供了GitHub项目地址。文章详细介绍了该软件的主界面风格、日程信息的分类查看功能,以及添加日程提醒和查看详情的界面。同时,作者还提醒了读者在使用过程中可能遇到的Android6.0权限问题,并提供了解决方法。 ... [详细]
  • Python中的PyInputPlus模块原文:https ... [详细]
  • React 小白初入门
    推荐学习:React官方文档:https:react.docschina.orgReact菜鸟教程:https:www.runoob.c ... [详细]
  • RN即ReactNative基于React框架针对移动端的跨平台框架,在学习RN前建议最好熟悉下html,css,js,当然如果比较急,那就直接上手吧,毕竟用学习前面基础的时间,R ... [详细]
  • 前言:原本纠结于Web模板,选了Handlebars。后来发现页面都是弱逻辑的,不支持复杂逻辑表达式。几乎要放弃之际,想起了Javascript中ev ... [详细]
  • 前言:原本纠结于Web 模板,选了Handlebars。后来发现页面都是弱逻辑的,不支持复杂逻辑表达式。几乎要放弃之际,想起了Javascript中eval函数。虽然eval函 ... [详细]
  • Vue cli2.0 项目中使用Monaco Editor编辑器
    monaco-editor是微软出的一条开源web在线编辑器支持多种语言,代码高亮,代码提示等功能,与VisualStudioCode功能几乎相同。在项目中可能会用带代码编 ... [详细]
  • Node.js详细安装及环境配置
    1、下载安装根据自己电脑系统及位数选择,我这里选择windows64位.msi格式安装包(官网:https:odejs.orgzh-cndownload).msi和.zip格式区别 ... [详细]
  • 技术周报·2021-05-07-小编推荐向现代Javascript转型原文标题:Publish,ship,andinstallmodernJavaScriptforfaste ... [详细]
  • 这篇“Webpack是怎么工作的”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大 ... [详细]
author-avatar
YYANNILl_242
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有