前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >chalk.js(node终端样式库)

chalk.js(node终端样式库)

作者头像
copy_left
发布2019-08-21 16:45:28
2.5K0
发布2019-08-21 16:45:28
举报
文章被收录于专栏:方球方球
github
基本格式

chalk.[.<style>...](string)

chalk[样式关键字_1][样式关键字_2](输出内容)

例子

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="javascript" contenteditable="true" cid="n33" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">const chalk = reuquire("chalk") const log = console.log ​ // 颜色字体 log( chalk.red("红色") ) ​ // 背景色 log( chalk.bgBlue("蓝色背景") ) ​ // 样式字体 log( chalk.bold("加粗") ) ​ // 多参数 log( chalk.blue("name", "age", "job") ) ​ // ES6 多行文本 log( // 多行文本将保留缩进格式 chalk.blue(name: Rogan age: ${25} job: ${ 'IT' }) ) ​ ​ // 其他颜色设置方式 log(chalk.keyword("orange")(' keyword ')) // 关键字 log(chalk.rgb(100, 100, 100)(' rgb ')) // rgb log(chalk.hex('#ffffff')(' hex ')) // hex ​ ​ ​ // 样式组合 log(colors: ${chalk.blue('blue')}, ${chalk.red('red')}) // 拼接 ​ log(chalk.blue.bold("Title")) // 链式组合 ​ log( chalk.bgYellow(error: ${chalk.red(" chalk is undefined ")}) ) // 嵌套 ​ ​ ​ // 自定义组合 const error = chalk.bgRed; const warning = chalk.yellow.bold;</pre>

样式api
  • reset - 样式重置
  • bold - 加粗
  • dim - 浅高亮
  • italic - 斜体
  • underline - 下划线
  • inverse- 反转前景和背景色
  • hidden - 隐藏内容
  • strikethrough - 删除线
  • visible- 显示chalk level > 0 的内容
前景色关键字(非全支持)
  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • blackBright (alias: gray, grey)
  • redBright
  • greenBright
  • yellowBright
  • blueBright
  • magentaBright
  • cyanBright
  • whiteBright
背景色关键字(非全支持)
  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite
  • bgBlackBright (alias: bgGray, bgGrey)
  • bgRedBright
  • bgGreenBright
  • bgYellowBright
  • bgBlueBright
  • bgMagentaBright
  • bgCyanBright
  • bgWhiteBright
取色模式
  • rgb - Example: chalk.rgb(255, 136, 0).bold('Orange!')
  • hex - Example: chalk.hex('#FF8800').bold('Orange!')
  • keyword (CSS keywords) - Example: chalk.keyword('orange').bold('Orange!')
  • hsl - Example: chalk.hsl(32, 100, 50).bold('Orange!')
  • hsv - Example: chalk.hsv(32, 100, 100).bold('Orange!')
  • hwb - Example: chalk.hwb(32, 0, 50).bold('Orange!')
  • ansi16
  • ansi256
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.08.07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • github
  • 基本格式
  • 例子
  • 样式api
  • 前景色关键字(非全支持)
  • 背景色关键字(非全支持)
  • 取色模式
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档