一般在浏览器中看到人家打印的带有颜色,所以咋也来实现一下。如下:
效果
在浏览器的效果
使用方式
console.log('\x1B[3m%s\x1B[23m', 'italic')
console.log('\x1B[1m%s\x1B[22m', 'bold')
在cmd里面的效果
使用方式
console.log('\x1B[3m%s\x1B[23m', 'italic')
console.log('\x1B[1m%s\x1B[22m', 'bold')
一些常用的颜色代码
'bold' : ['\x1B[1m%s\x1B[22m'],
'italic' : ['\x1B[3m%s\x1B[23m'],
'underline' : ['\x1B[4m%s\x1B[24m'],
'inverse' : ['\x1B[7m%s\x1B[27m'],
'strikethrough' : ['\x1B[9m%s\x1B[29m'],
'white' : ['\x1B[37m%s\x1B[39m'],
'grey' : ['\x1B[90m%s\x1B[39m'],
'black' : ['\x1B[30m%s\x1B[39m'],
'blue' : ['\x1B[34m%s\x1B[39m'],
'cyan' : ['\x1B[36m%s\x1B[39m'],
'green' : ['\x1B[32m%s\x1B[39m'],
'magenta' : ['\x1B[35m%s\x1B[39m'],
'red' : ['\x1B[31m%s\x1B[39m'],
'yellow' : ['\x1B[33m%s\x1B[39m'],
'whiteBG' : ['\x1B[47m%s\x1B[49m'],
'greyBG' : ['\x1B[100m%s\x1B[49m'],
'blackBG' : ['\x1B[40m%s\x1B[49m'],
'blueBG' : ['\x1B[44m%s\x1B[49m'],
'cyanBG' : ['\x1B[46m%s\x1B[49m'],
'greenBG' : ['\x1B[42m%s\x1B[49m'],
'magentaBG' : ['\x1B[45m%s\x1B[49m'],
'redBG' : ['\x1B[41m%s\x1B[49m'],
'yellowBG' : ['\x1B[43m%s\x1B[49m']
本文使用 文章同步助手 同步