Marak / colors.js

get colors in your node.js console
https://github.com/Marak/colors.js
Other
5.17k stars 446 forks source link

Keep colors when not a TTY #199

Closed trufae closed 6 years ago

trufae commented 7 years ago

I want to use | less -R with a program im using colors.js, by reading the checks in index.js there's no way to override this behaviour because the isTTY chk is done before the env var check, so the user have no choice to scroll with less.

Also, using colorized output of colors.js with less -R results in only the first line colorized, because the ansi escape codes should be done on every single line, instead of the whole string. I have workarounded this in my code, but will be good if colors.js could handle that too, this is probably a separate issue

beether commented 6 years ago

I spent two hours trying to figure out why I couldn't capture color in a node process I was spawning. First of all, node is crap. You can use spawn with {stdio: 'inherit'} to preserve colors, but then you have no way of capturing the the actual f***ing output. It goes straight to stdout with no way to intercept it.

Secondly, it's astonishing that this library would forcibly disable itself with no way to prevent it from happening. Luckily, I coded the script whose output I was trying to capture, so I changed everything to chalk, which sensibly provides an env way to enable it, and I will never look back.

I just hope I'm never in the situation where I need to capture output from some process that uses colors, because I'd have no idea what to do. Hours of googling yields no results. {stdio: 'inherit'} gets me halfway there, but then I'm stuck.

Node f***ing blows.

jaredallard commented 6 years ago

https://github.com/Marak/colors.js/blob/cc857f297748633785b2bcf555f226930c8dee4d/lib/system/supports-colors.js#L39

Have you tried FORCE_COLOR=1? EDIT Git blame says this was added a month ago. So I guess this issue is closed?

givehug commented 6 years ago

FORCE_COLOR works if I define colors manually eg console.log('\x1b[36m', 'sometext' ,'\x1b[0m'); But not with colors package.

UPDATE: it works in v1.3.0 !

DABH commented 6 years ago

We have fixed the multiline coloring issue OP mentioned, and that FORCE_COLOR check should be more robust too. Sounds like things are working for people (woo!), feel free to open another issue if you run into any specific examples that aren't working. Thanks!