chalk
基础使用
- 输出一条带颜色的提示
import chalk from "chalk";
import { log } from "console";
log(chalk.hex("#E438E6").bold(`选择需要的项目模板:`));
官方用例:
import chalk from 'chalk';
const log = console.log;
// Combine styled and normal strings
// 多颜色拼接
log(chalk.blue('Hello') + ' World' + chalk.red('!'));
// Compose multiple styles using the chainable API
// 红底篮子的粗体
log(chalk.blue.bgRed.bold('Hello world!'));
// Pass in multiple arguments
// 传入多个参数时,会用空格作为分隔输出
log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));
// Nest styles
// 多样式嵌套拼接
log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));
// Nest styles of the same type even (color, underline, background)
log(chalk.green(
'I am a green line ' +
chalk.blue.underline.bold('with a blue substring') +
' that becomes green again!'
));
// ES2015 template literal
// 支持 换行
log(`
CPU: ${chalk.red('90%')}
RAM: ${chalk.green('40%')}
DISK: ${chalk.yellow('70%')}
`);
// Use RGB colors in terminal emulators that support it.
log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
log(chalk.hex('#DEADED').bold('Bold gray!'));