question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Color is not preserved when stdout is redirected

See original GitHub issue

Hey, 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:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sammndhrcommented, Nov 27, 2019

Run node main.jsx > tmp.txt --color instead of node main.jsx > tmp.txt to preserve the log colors.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found