That’s pretty nasty - this article is factually incorrect in probably the worst way: the code will work on author’s computer, but not for other people [0] Not to mention that it is missing “good citizen” features like turning off colors when stdout is not a tty. [0] https://news.ycombinator.com/item?id=18125374
Better solution: do not detect whether your output is a tty or not.
Let the user decide they want colors or not by using `--color=always` or `--color=never` or similar.
There's few things worse than writing a script and getting different output just because you're no longer running the program interactively.