Color is not preserved when stdout is redirected
See original GitHub issueHey, thank you for this package, it is really great. In one of my projects, I took a dependency on ink-quicksearch, which took a dependency on ink, which took a dependency on chalk, which brought me here.
The issue I am facing is when I combine a npm script with pipes and redirrects, as that removes the color.
I have a repro below. To make it easier, I am printing to stderr and I am redirecting the stdout.
#!/usr/bin/env node
const chalk = require('chalk');
console.error('\x1b[36m%s\x1b[0m', 'This text will be printed colorful');
console.error(chalk.blue('This text is white :('));
Then run as
node main.jsx # This works as expected
node main.jsx > tmp.txt # Bug here
Is this something easy to fix? If not, do you find this to be an issue or a feature? If it is an issue, I can invest time and fix it, just wanted to make sure it is not like this by design.
Thanks!
Edit: I am using gnome-terminal
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Preserving color when redirecting output from stdout and ...
I am wrapping a command line process in a WinForms app and redirecting the output so it can be piped into either an...
Read more >stdin/stderr redirection, piping and color - Unix StackExchange
A pipe or redirection won't remove any colors! The initial command that you're using removes the colors when it notices that the output...
Read more >Preserve text color while redirecting output from a process to a ...
Hi, I am trying to develop a C# application which runs a process and displays the output of the process on a text...
Read more >How to Write Stdout to a File with Colors | Baeldung on Linux
In this tutorial, we'll cover some tools we can use to write standard output to files while preserving their colors.
Read more >color=always) except when redirecting the output to a file ...
In my Kubuntu [ -f /dev/stdout ] can be used to tell if stdout is a regular file. This leads to the following...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://github.com/chalk/chalk#chalksupportscolor
Run
node main.jsx > tmp.txt --color
instead ofnode main.jsx > tmp.txt
to preserve the log colors.