bevacqua bevacqua - 4 months ago 9
Node.js Question

Formatting lost down the pipes

You can give it a ride yourself, below is the code in copy-able format.

Here's

chalked.js


var chalk = require('chalk');

console.log('Immediately!');

setTimeout(function () {
console.log(chalk.red('Right after!'));
}, 400);

setTimeout(function () {
process.stdout.write('And ' + chalk.magenta('...'));

setTimeout(function () {
console.log(chalk.underline('it\'s gone!'));
}, 2000);
}, 5000);


Then there's
piper.js


process.stdin.pipe(process.stdout);


enter image description here

How can I preserve color formatting through these pipes?

Answer

So far as I can tell, Chalk disables colour support when not writing to a TTY. It looks like you need to supply the --color arg.

You can also set the environment variable FORCE_COLOR=1 to force colors for anything that uses Chalk.