I work in the terminal a lot and I often want to write programs that
color their output a bit. For example, perhaps I’m looking at a sequencing read and I want to know what
part of it was the reason it was flagged. I could use
colorama,
termcolor, or another
library, but
including a
dependency for something this simple is not really worth
it. Instead, printing colored text is as simple as:
I usually just want one or two highlight colors, typically in bold,
and rarely find the six standard colors limiting. It’s especially
helpful if you want to draw your eye to something specific, while
maintaining the context around it when you need to look further.
How compatible is this? Will someone with a non-ANSI terminal someday
run my code and complain? One data point is that I wrote icdiff with this approach in 2009, and it’s been reasonably
popular. While I’ve gotten hundreds
of bug reports this has never been one people have complained about.
Simple Terminal Colors
Link post
I work in the terminal a lot and I often want to write programs that color their output a bit. For example, perhaps I’m looking at a sequencing read and I want to know what part of it was the reason it was flagged. I could use colorama, termcolor, or another library, but including a dependency for something this simple is not really worth it. Instead, printing colored text is as simple as:
I usually just want one or two highlight colors, typically in bold, and rarely find the six standard colors limiting. It’s especially helpful if you want to draw your eye to something specific, while maintaining the context around it when you need to look further.
How compatible is this? Will someone with a non-ANSI terminal someday run my code and complain? One data point is that I wrote icdiff with this approach in 2009, and it’s been reasonably popular. While I’ve gotten hundreds of bug reports this has never been one people have complained about.
Comment via: facebook, mastodon