码迷,mamicode.com
首页 > 其他好文 > 详细

node 在控制台打印有色彩的输出

时间:2017-11-27 12:46:59      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:style   under   学习   path   就会   line   console   hit   gre   

在学习 node 过程中,因为没有找到有断点的调试方法,只能退而次之,在控制台打印调试。

但整个控制台的输出都是一种颜色,有时候很难找到自己需要的信息,这时,有颜色的打印就会帮上很大的忙。

console.log(‘\x1B[36m%s\x1B[0m‘, info);  //cyan  
console.log(‘\x1B[33m%s\x1b[0m:‘, path);  //yellow  
var styles = {  
    ‘bold‘          : [‘\x1B[1m‘,  ‘\x1B[22m‘],  
    ‘italic‘        : [‘\x1B[3m‘,  ‘\x1B[23m‘],  
    ‘underline‘     : [‘\x1B[4m‘,  ‘\x1B[24m‘],  
    ‘inverse‘       : [‘\x1B[7m‘,  ‘\x1B[27m‘],  
    ‘strikethrough‘ : [‘\x1B[9m‘,  ‘\x1B[29m‘],  
    ‘white‘         : [‘\x1B[37m‘, ‘\x1B[39m‘],  
    ‘grey‘          : [‘\x1B[90m‘, ‘\x1B[39m‘],  
   ‘black‘         : [‘\x1B[30m‘, ‘\x1B[39m‘],  
    ‘blue‘          : [‘\x1B[34m‘, ‘\x1B[39m‘],  
    ‘cyan‘          : [‘\x1B[36m‘, ‘\x1B[39m‘],  
    ‘green‘         : [‘\x1B[32m‘, ‘\x1B[39m‘],  
    ‘magenta‘       : [‘\x1B[35m‘, ‘\x1B[39m‘],  
    ‘red‘           : [‘\x1B[31m‘, ‘\x1B[39m‘],  
    ‘yellow‘        : [‘\x1B[33m‘, ‘\x1B[39m‘],  
    ‘whiteBG‘       : [‘\x1B[47m‘, ‘\x1B[49m‘],  
    ‘greyBG‘        : [‘\x1B[49;5;8m‘, ‘\x1B[49m‘],  
    ‘blackBG‘       : [‘\x1B[40m‘, ‘\x1B[49m‘],  
    ‘blueBG‘        : [‘\x1B[44m‘, ‘\x1B[49m‘],  
    ‘cyanBG‘        : [‘\x1B[46m‘, ‘\x1B[49m‘],  
    ‘greenBG‘       : [‘\x1B[42m‘, ‘\x1B[49m‘],  
    ‘magentaBG‘     : [‘\x1B[45m‘, ‘\x1B[49m‘],  
    ‘redBG‘         : [‘\x1B[41m‘, ‘\x1B[49m‘],  
    ‘yellowBG‘      : [‘\x1B[43m‘, ‘\x1B[49m‘]  
};  

 

node 在控制台打印有色彩的输出

标签:style   under   学习   path   就会   line   console   hit   gre   

原文地址:http://www.cnblogs.com/fenghen/p/7903472.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!