92

How to Choose Colors for Your CLI Applications (2023)

A confused user once stopped by, they had a blank terminal, so I showed them how to select all which revealed the helpfully black on black text. These days I compile colour support out of st, or set *colorMode:false for xterm. "But you can customize the colours" is a typical response, to which one might respond that one has grown weary of pushing that particular rock, and moreover one may be busy with other things at a drag-out monitor in a server room at three in the morning that has helpfully dark blue text on a black console, or worse if some high-minded expert has gone and rubbed the backside of a unicorn everywhere so that they may improve the "legibility".

9 minutes agotolciho

As long as CLI programs stick to the 8 or 16 standard colors and refrain from setting background colors (inverse mode is fine), as well as from explicitly setting white or black as text color, everyone can reasonably configure their terminal colors so that everything is readable.

When going beyond that, the colors really need to be configurable on the application.

an hour agolayer8

> refrain from setting background colors

That's the thing though, setting bg color opens up a lot of options, and constraining to invert is not sufficient in my opinion.

3 minutes agoJohnLeitch

Colourful terminals are so useful. I have mine colour coded according to the working directory depending on the project. So I can see which terminal is associated with which project even if there are twenty terminals open. The scripts are even in my servers so when I ssh in to them it changes colour as well.

https://michael.mior.ca/blog/coloured-ssh-terminals/

an hour agos_dev

I really think we should converge to semantic codes. By example Background is zero, standard is 7, positive / negative, highlight, colored1,2,3 .. with correct defaults, and let the user have a common 8 or 16 colors palette in the terminal for all textmode apps. Imagine having some kind of unified color themes in the terminal.

13 minutes agomakapuf

If you want a quick easy way to add some colors to your own shell scripts:

    export STDOUT_COLOR_START=''
    export STDOUT_COLOR_STOP=''
    export STDERR_COLOR_START=''
    export STDERR_COLOR_STOP=''
In your shell script:

    print_stdout() {
        printf %s%s%s\\n "${STDOUT_COLOR_START:-}" "$*" "${STDOUT_COLOR_STOP:-}"
    }

    print_stderr() {
        >&2 printf %s%s%s\\n "${STDERR_COLOR_START:-}" "$*" "${STDERR_COLOR_STOP:-}"
    }
Source: https://github.com/sixarm/unix-shell-script-kit

The source also has functions for nocolor, and detecting a dumb terminal setup that doesn't use colors, etc.

24 minutes agojph

1. That script's color check doesn't check that the output is a terminal. Also test

    tty -s

2. Don't hardcode escape sequences. Use (e.g.)

    export STDOUT_COLOR_START="`tput setaf 4`".
11 minutes agokps

What is the purpose of making everything the same color?

20 minutes agodirewolf20

stdout and stderr get different colors.

18 minutes agoRygian

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.

3 hours agoj4cobgarby

Hard disagree on the red/green. Use whatever you think appropriate and make it user configurable.

2 hours agoBeetleB

It's a CLI app, it's already configurable. Every good terminal emulator lets you set custom palettes.

2 hours agomrob

>Every good terminal emulator lets you set custom palettes

Not differently for each program's output.

an hour agokps

Which is a good reason to stick with the de-facto standard of red for bad and green for good.

an hour agomrob

unless you're colour blind

an hour agosceptic123

If you're color blind, you change the palette in your terminal emulator so "red" and "green" become different colors you can distinguish. It even works for rarer forms of color blindness. This works best when people follow the de-facto standard.

33 minutes agomrob

Red here does not mean #ff0000. it means color 1. in the 4 bit colors palette

29 minutes agoskydhash

Color is cultural. Red is associated with good in China

an hour agofassssst

Context here matters, red finds its way into Chinese forbidden or warning signs quite often.

44 minutes agoaltcognito

Eh, LS_COLORS is sometimes useful once the meanings are in your subconscious.

2 hours agored_admiral

> 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.

2 hours agobusterarm

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 adding more mental overhead for the user, not less.

2 hours agoEtheryte

You are ignoring that most people already have a cultural understanding of the colors red and green. Changes done for accessibility should never making things worse for the average user.

an hour agoaccount42

More importantly, dont use color as sole source of information. Strikethrough, emoji or ok / bad can also be used.

2 hours agomakapuf

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.

2 hours agoxenophonf

Yes that's why I also mentioned text labels. (strikethrough ansi codes aren't also fun to type). Besides, where are you needing 7but clean data ? Isn't that a narrow use case ?

19 minutes agomakapuf

> They're hard to type

I'd like to recommend rofimoji. I have it bound to a hotkey, so whenever I want to type an emoji, I just hit that hotkey and then a window pops up with my most recent emoji already visible at the top. Then I start typing in words that describe the emoji that I want like "crying" and it filters the list. Finally I select one and it pastes it into whatever text box I had selected before I hit the hotkey. My only complaint is I wish it worked for all unicode codepoints instead of just the emoji.

2 hours agocraftkiller

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.

2 hours agoskydhash

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.

2 hours agotczMUFlmoNk

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.

2 hours agomrob

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.

2 hours agoskydhash

I'm a bit color blind and it might be quite common to show errors in red but when the background is black, I can't see it at all.

an hour agojammcq

Neither can I. Luckily tweaking the colours can make it somewhat readable. (Sometimes…)

an hour agobradrn

There's an ever more basic rule: don't just make your text white (ANSI 37m) because you assume the terminal will have a dark background. Even white-on-black (37;40m), while usually readable, can stand out the wrong way if you assume that everyone is using dark mode.

2 hours agored_admiral

IMO if your terminal theme does not provide high contrast for "white" text on the default or "black" backgrounds, that's for you to fix. If you want a light terminal then change the color scheme to map "black" to a bright color and "white" to a dark color while making sure that other colors have good contrast to your "black". Don't just change the default foreground and background color and expect every single color using program to fix your mess.

2 hours agoaccount42

Interesting analysis, but perhaps it warrants a different conclusion: it's almost impossible to please everyone in this case. The resulting colours seem of some utility, but if you intend to make something more interesting you're probably annoy some (potentially large) group, in the case of legacy terminal coloring.

37 minutes agothinking_cactus

I used solarized since it came out but I dropped it some years back. I don’t think I can use it for dark mode. It’s too washed out and dull compared to light mode which is what I used to use it with. I just use whatever VS Code or VIM gives me as a dark mode and it’s usually better.

35 minutes agohnsmhthrow

I recently spent several evenings re-working all of my colours across all of my computers and screens; terminals, IDEs, etc. Ultimately, despite using the same tools, and always dark mode, across all of my machines, the setup for each was different.

I think it's safe to set a standard colour-set so that it's immediately usable, but beyond that, a user should be customising to their requirements.

Perception differs among people; many of the colours OP listed as unreadable, were barely an issue, bright yellow being the only one I could unequivocally agree on. Perhaps display type, configuration and colour calibration is an important factor, as well as individual perception, ambient conditions, brightness levels, contrast, and perhaps even more variables have a significant effect.

I've also learned, since adding an OLED Monitor to my desk alongside the IPS ones, that it's possible to have too much contrast; brightly coloured text alongside pixels that are literally off can be just as problematic to read at times, as low-contrast.

an hour agoalias_neo

As long as you respect the NO_COLOR variable, it will work for me.

https://no-color.org/

29 minutes agoori_b

If the goal of the post is to pick 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 really limiting for color choice (there's no such thing as "dark yellow" for example), and lowers the maximum contrast you can have for text because you get the best contrast when one color is dark and the other is light.

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

2 hours agoseanwilson

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

The responsibility for this lies with the color scheme not the terminal program.

2 hours agoaccount42

CLI apps can detect the background color of the terminal, and determine contrasting colors accordingly.

an hour agoJoshTriplett

They can? Is this a recent thing? I remember wanting to detect the background colour years ago, and not finding any way to do it.

an hour agotakluyver

It's not recent, and most terminals support it. You send an escape sequence to the terminal, and get back a sequence that tells you the exact background color.

an hour agoJoshTriplett

That's called `\e[0;92m`, aka the ANSI terminal espace sequence for bright green. You have 15 others, that will be displayed however the terminal's user wants. They're already available in most terminal color libraries, too.

2 hours agoalt187

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.

2 hours agosroussey
[deleted]
2 hours ago

It's 2026, and app developers are solely responsible for not causing eyehurt, even if their users insist on using the Hotdog Stand theme.

2 hours agobitwize

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.

2 hours agoxenophonf

Yeah. "The only winning move is not to play".

19 minutes agodavidw

I dislike when devs only try to detect if it’s a tty, then enable all their gimmicks without even providing a flag. Not everything is xterm-256color.

36 minutes agoskydhash

[dead]

an hour agomaximgeorge

[flagged]

2 hours agothe_gipsy

It's easier to see dark text on a light background for people with astigmatism.

2 hours agotaswellian

Or for people working outside. Or for people using an e-ink display.

an hour agoJoshTriplett

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...

2 hours agoArch-TK

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).

2 hours agostrogonoff

> 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.

2 hours agoskydhash

Can you work this into an AGENTS.md ? Just so happen to be working on multiple TUI at the moment: text-based modern web browser, VPS rental console, agentic coding wrapper.

Colors, have been a perpetual nightmare.