Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用chalk NPM模块的终端样式(控制字符)_Node.js_Npm_Control Characters_Chalk - Fatal编程技术网

Node.js 使用chalk NPM模块的终端样式(控制字符)

Node.js 使用chalk NPM模块的终端样式(控制字符),node.js,npm,control-characters,chalk,Node.js,Npm,Control Characters,Chalk,假设我有这个: //exp.js const chalk = require('chalk'); console.log(chalk.red('foobar')); 然后我在命令行上运行: node exp.js | cat 在我见过的所有案例中,颜色都不会显示出来。有人知道为什么吗?有没有办法让颜色显示出来?我做错什么了吗 我唯一的猜测是,当进程连接到管道中时,库“关闭”字符串样式 例如: 根据: 或: 这是粉笔库的来源-不要评论你的问题,但一定要编辑它以改进,他们不应该这样做。对问题的评

假设我有这个:

//exp.js
const chalk = require('chalk');
console.log(chalk.red('foobar'));
然后我在命令行上运行:

node exp.js | cat
在我见过的所有案例中,颜色都不会显示出来。有人知道为什么吗?有没有办法让颜色显示出来?我做错什么了吗

我唯一的猜测是,当进程连接到管道中时,库“关闭”字符串样式

例如:

根据:

或:


这是粉笔库的来源-不要评论你的问题,但一定要编辑它以改进,他们不应该这样做。对问题的评论保留给其他人。我编辑了你的问题以添加链接,但你应该这样做。顺便说一句,该库(我正在发现)文档“自动检测颜色支持”。我建议在他们的github中添加一个问题。这个问题的URL也应该进入这个问题。基本上,你应该禁止自己评论自己的问题。哦,是的,一定是这样
$ node exp.js --color | cat
$ env FORCE_COLOR=1 node exp.js | cat
//exp.js
process.env.FORCE_COLOR = '1';
const chalk = require('chalk');
console.log(chalk.red('foobar'));