Choosing readable ANSI colors for CLIs
Earlier today Julia Evans asked for “some examples of programs which don’t do well with a light background”. My (mostly ancient) experience here is attempting to have reasonable colour usage out of my bunyan
and ecslog
tools for pretty-printing log files. I use iTerm2 on macOS with the default “Light Background” color preset. I have occasionally noted programs that generate output with colors that don’t work for me. Julia’s post was a good kick for me post some of the screenshots I’ve collected. (And to post to a blog that I haven’t touched in 8 years.)
When I say “colour” (or “color” for some of y’all), I really mean ANSI Select Graphic Rendition (SGR) parameters, which includes more than just colours – bold, italics, blink (!), “bright” or high-intensity colors, etc. I’ve have typically limited my usage to a few colours, and some usage of bold.
tl;dr limited colour advice
A set of guidelines for ANSI style/colour usage. These are limited to my experience, which is restricted and old.
- Avoid blue, because it is not visible on cmd.exe on Windows. (It has been over a decade since I used Windows regularly, so this might be out of date.)
- Avoid bright yellow and bold yellow. The contrast with a white background, e.g. on the “Light Background” default preset for iTerm2 and Terminal.app on macOS, is too low, making the text unreadable. Note that plain “yellow” – not bolded or bright – is fine.
- Avoid grey. It is the same colour as the background on the Solarized Dark theme from https://github.com/altercation/solarized. (See node-bunyan#160 and solarized#220.
Examples of poor colours on a light background
Here are some examples, with screenshots, of programs that use colours/styles in the terminal that are problematic for readability. Some of these might be outdated. I hadn’t noted program version or the date when collecting these. Also, bad me for never having opened issues on these projects regarding the colour issue.
Webpack using bright yellow.
npm install
using bright yellow for the count of moderate vulnerabilities.
nvm ls
using bright yellow for some aliases.
Maven test output using bright yellow.
az login
using bright yellow.
az
is the Azure CLI
Links
- https://no-color.org/ is an interesting effort to attempt to standardize the
NO_COLOR=1
environment variable for programs to disable their ANSI colouring. - My Go-lang code for doing ANSI colouring: https://github.com/trentm/go-ecslog/blob/main/internal/ansipainter/ansipainter.go#L3-L7
- My (old) Node.js code for doing ANSI colouring: https://github.com/trentm/node-bunyan/blob/master/bin/bunyan#L655-L691