项目作者: jaywcjlove

项目描述 :
ಠ_ಠ Terminal string styling done right.
高级语言: JavaScript
项目地址: git://github.com/jaywcjlove/colors-cli.git
创建时间: 2016-05-20T18:30:50Z
项目社区:https://github.com/jaywcjlove/colors-cli

开源协议:

下载


colors-cli

Buy me a coffee

build
NPM Downloads

Terminal string styling done right. ಠ_ಠ

Install with npm:

  1. npm install colors-cli --save-dev

Styles

boldfaintitalicunderlineblinkoverlineinverseconcealstrike

Colors





































































ForegroundBackgroundBright ForegroundBright Background
black black_b black_bt black_bbt
red red_b red_bt red_bbt
green green_b green_bt green_bbt
yellow yellow_b yellow_bt yellow_bbt
blue blue_b blue_bt blue_bbt
magenta magenta_b magenta_bt magenta_bbt
cyan cyan_b cyan_bt cyan_bbt
white white_b white_bt white_bbt

Basic usage:

Output colored text:

  1. var color = require('colors-cli')
  2. console.log( color.red('hello') )

Best way is to predefine needed stylings and then use it:

  1. var color = require('colors-cli/safe')
  2. var error = color.red.bold;
  3. var warn = color.yellow;
  4. var notice = color.blue;
  5. console.log(error('Error!'));
  6. console.log(warn('Warning'));
  7. console.log(notice('Notice'));

Styles can be mixed:

  1. var color = require('colors-cli/safe')
  2. console.log('=>', color.red.bold.underline('hello') )
  3. console.log('=>', color.magenta_bt.underline('hello ' + color.blue_bt('wo' + color.yellow_bt.magenta_bbt('r') + 'ld') + ' !!!!'));
  4. console.log('=>', color.magenta_bt.underline('hello ' + color.blue_bt('wo' + color.yellow_bt.magenta_bbt('r'))));
  5. console.log('=>', color.magenta_bt.underline('hello ' + color.blue_bt('world') + ' !!!!' + color.yellow('kenny') + ' wong' ));
  6. var color = require('colors-cli/safe')
  7. require('colors-cli/toxic')
  8. console.log('=> ' + color.underline('$ ' + 'npm'.magenta.underline + ' install'.yellow.underline + ' colors-cli --save-dev'));
  1. require('colors-cli/toxic')
  2. console.log( 'hello'.green );
  3. console.log( 'hello'.green.black_b.underline );
  4. console.log('=> $'.green + ' npm '.magenta + 'install '.yellow + 'colors-cli'.cyan + ' --save-dev');

ANSI 256 colors

Support ANSI 256 colors. [0 - 255], The rules of method name.

  • Foreground x32
  • Background xb32
  1. var color = require('colors-cli/safe')
  2. console.log( color.x45.bold.underline('hello') )
  3. require('colors-cli/toxic')
  4. console.log( 'hello'.x23.underline );
  5. console.log( 'hello'.green.xb34.underline );

Use the command line

  1. Usage: colors
  2. Options:
  3. --black => black
  4. --black_b => black_b
  5. --red => red
  6. ...
  7. Examples:
  8. colors --red "\nhello world" --bold,underline,yellow "wcj"
  9. colors --green,bold "\nhello world"
  10. colors --x12,bold "hello world"

Reference

The ANSI Escape sequences control code screen.

  1. echo -e "\033[31;41;4m something here 33[0m"

\033 As the escape character, inform the terminal to switch to the escape mode.
[ The beginning of the CSI.
m Make the action to be performed.
; ASCII code separator.

License

Licensed under the MIT License.