How to Choose Colors for Your CLI Applications (2023)
41 points
1 hour ago
| 5 comments
| blog.xoria.org
| HN
seanwilson
40 seconds ago
[-]
If you're trying to pick a fixed set of terminal colors that contrast on both white/light and black/dark backgrounds, it means you're stuck with midtone colors (between light and dark). This is pretty limiting.

Ideally, instead of the CLI app switching to "bright green", it would pick a "contrasting green". So if the terminal background was dark, it would pick bright green, and for light background it would pick dark green. This is similar to how you'd implement dark mode in a web app.

I'd be interested to see examples, but I can't think of any web app I've seen where dark/light mode was implemented by only changing the background color. It would be really limiting there too.

reply
j4cobgarby
45 minutes ago
[-]
Use only default (white/black), red for bad, green for good. If you need more than that, like vim or whatever, then maybe a 'fullscreen' TUI is better, with a specified background and foreground. For CLI tools, I'm not sure if I prefer more colours.

The CSS to make the terminals look like iTerm was smooth, to the point I read them as screenshots.

reply
BeetleB
1 minute ago
[-]
Hard disagree on the red/green. Use whatever you think appropriate and make it user configurable.
reply
busterarm
30 minutes ago
[-]
> red for bad, green for good

8% of men of Northern European descent (and 0.4% of women) are red-green colorblind. That'd be a terrible choice. Use blue-orange, blue-red, or purple-green.

reply
Etheryte
43 seconds ago
[-]
This approach is worse. Use red and green like everyone else and the user can choose their terminal color palette to differentiate in a way that works for them. Then it works the same across all commands. If you're the odd one out, you're creating more work for the user, not less.
reply
makapuf
25 minutes ago
[-]
More importantly, dont use color as sole source of information. Strikethrough, emoji or ok / bad can also be used.
reply
xenophonf
8 minutes ago
[-]
Emojis aren't 7-bit clean. They're hard to type. They don't mean things the same way words do. `foo | grep -i error` communicates intent better than `foo | grep :-/` or whatever goofy hieroglyph someone chose instead of, like, a word with clearly defined meaning.
reply
skydhash
17 minutes ago
[-]
Red/green is semantic in these cases. They’re user configurable in almost all terminals, so there’s no real accessibility issue. I tend to associate blue with decorative accent, yellow with info/warning text, and cyan and magenta for really fancy stuff.
reply
tczMUFlmoNk
13 minutes ago
[-]
Red/green has no inherent semantics. It has the semantics that you assign it. If you choose to assign it meaning that disenfranchises 8% of men using your system, that's your choice, but it is not a good one.
reply
mrob
1 minute ago
[-]
The standard terminal palette is only 16 colors. Even if you compress them all into the green-to-blue color range, it's still possible to distinguish all 16. The user can change "red" and "green" to whatever they like in the terminal preferences and then every 16-color app will be accessible with no additional effort from anybody.
reply
skydhash
7 minutes ago
[-]
Cultural semantics (diff tools, build tools,…: green/addition/ok, red/removal/error). And people with color blindness can alter the colors to something they can differentiate. And in the ansi sequences, they are actually numbers.
reply
sroussey
10 minutes ago
[-]
This is true for the console in dev tools as well.

Problem there is you can’t change css so at the moment the systems color preference changes thing will look bad.

Important considerations for custom formatters.

reply
sroussey
2 minutes ago
[-]
Here is a screenshot for my personal example:

https://github.com/workglow-dev/workglow/blob/main/docs/deve...

Play with it here using dev tools (you can ignore the website itself): https://workglow-web.netlify.app/

Docs including útil for checking dark mode: https://github.com/workglow-dev/workglow/tree/main/packages/...

reply
xenophonf
12 minutes ago
[-]
I really wish you wouldn't. All the rinky dink colors and animations screw with the CLI output when you don't correctly detect whether the user's running the app interactively.

Keep it plain text. Regular, old, boring output is good.

reply
the_gipsy
33 minutes ago
[-]
Just ignore white background terminals. People who use white themed terminals are psychopaths anyway, they endure seeing fucked up colors all the time.
reply
Arch-TK
29 minutes ago
[-]
Most things work fine with black on white terminals.

If your software does something dumb when my theme switches to black on white during the day then I am just going to avoid using it...

reply
taswellian
15 minutes ago
[-]
It's easier to see dark text on a light background for people with astigmatism.
reply
strogonoff
13 minutes ago
[-]
Accommodating terminal colour schemes, however crazy to you they might be—white on black, black on white, dark brown on off-white Solarized-style, etc.—is basics of TUI design.

Personally I alternate between light on dark and dark on light (the latter sometimes together with OS-wide colour inversion feature).

reply
skydhash
12 minutes ago
[-]
> People who use white themed terminals are psychopaths anyway

Dark background is hell for anyone with astigmatism. It’s fine with 80x24 (vga text mode), but for anything higher feels like light needles on the retina. With astigmatism everything that is bright and small is duplicated, which means small characters is very difficult to read.

reply