FORCE_COLOR: Keep Your Command Line Colorful, Even when Piping - Retain Text Colors in Logs, Output Streams, and More
4 points by pzel
4 points by pzel
This might be a controversial post to submit (lobste.rs not lacking in those lately), but I somehow feel like the people behind this hate me and everyone like me.
Now, nodejs will stop respecting your NO_COLOR env var that you set up yourself, because one of the many libraries inside your node_modules flips FORCE_COLOR to true on its own. The entire point of NO_COLOR was to opt out of this madness completely, but it seems that the madness never stops... Are we now supposed to set up the website NO_FORCE_COLOR to override this one?
It's made even worse by the fact that setting FORCE_COLOR to 0 or even the empty string is equivalent to turning it on. This is cruel beyond belief.
FORCE_COLOR= npx playwright test ./tests
(node:21045) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
(Use `node --trace-warnings ...` to show where the warning was created)
At least the empty string thing seems to be a node bug: https://force-color.org/#:~:text=and%20not%20an%20empty%20string
the year is 2040, we got a tower of color-switching environment variables and no one has an idea of how the whole thing works…
FORCE_FORCE_FORCE_FORCE_FORCE_COLOR
FORCE_FORCE_FORCE_FORCE_NO_COLOR
NO_FORCE_FORCE_FORCE_FORCE_COLOR
FORCE_FORCE_FORCE_FORCE_COLOR
FORCE_FORCE_FORCE_NO_COLOR
NO_FORCE_FORCE_FORCE_COLOR
FORCE_FORCE_FORCE_COLOR
FORCE_FORCE_NO_COLOR
NO_FORCE_FORCE_COLOR
FORCE_FORCE_COLOR
FORCE_NO_COLOR
NO_FORCE_COLOR
FORCE_COLOR
NO_COLOR
The reasoning is also strange. The stated purpose is to communicate to programs that you can't easily control directly that they shouldn't disable colour for incidental reasons, such as not writing to a TTY. Because NO_COLOR is for if you want no colour at all, clearly NO_COLOR should override FORCE_COLOR? Why the other way round?
one of the many libraries inside your node_modules flips FORCE_COLOR to true on its own
Well it shouldn't, same as such a library shouldn't enable NO_COLOR on its own. A library can also open /dev/tty and run stty to set weird terminal properties; it also shouldn't do that. The fact that bad software can do bad things doesn't mean that the technology is bad.
Yes, ultimately I think it comes down to respecting Jef Raskin's dictum that "user input is sacred". It's especially jarring in the case of usability/accessibility-adjacent functionality, where it's your duty to accommodate people's preferences.
Of course color in the terminal is a minor annoyance, but imagine someone had epilepsy and set NO_FLASHING_COLORS, and then you come along and write code that overrides that setting if someone else --somewhere in the chain-- says FORCE_FLASHING_COLORS. Not respecting opt-outs is just user-hostile behavior.
The fact that bad software can do bad things doesn't mean that the technology is bad.
Oh for sure, I have nothing against terminal colors, cursor addressing and stty magic, but I prefer those to be only used in 'TUI-style' applications. Case in point: nethack, k9s, elinks, etc. I can just open a dedicated terminal with all the colors enabled. But for regular cli work, I think it's an overreach for tools to tweak their own visual dials. The terminal was not made for this.
I thought this was joking, but it's apparently real:
Oh yeah it's real, and my head is reeling from the sheer blast radius. It turns out Playwright has seventeen issues mentioning this flag.
I suspect that this is a troll project run wild, which helps a bit with the engineering vertigo.
Actually opening all those issues and submitting patches is just wild to me. Like, I can easily understand making a web page as a funny reaction to NO_COLOR. But this is a lot. I hope you're right and it's trolling that escaped into the wild.
Sadly it's all in earnest. I think I need to take a break after reading parts of the design discussion, full of tasteful wisdom such as:
The reason NO_COLOR came to be in the first place is because some people dislike colored output and want to be able to disable it at the shell profile level. They wouldn't want or expect for it to stop other things like animated progress bars and other fancy output from working correctly.
I hope Rob Pike drops down the chimney on Christmas Eve and gives the author a huge lump of coal and a stern talking-to about progress bars and other tty abuses.