How to Choose Colors for Your CLI Applications (2023)

Posted by kruuuder 3 hours ago

Counter91Comment56OpenOriginal

Comments

Comment by tolciho 5 minutes ago

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

Comment by layer8 1 hour ago

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.

Comment by s_dev 44 minutes ago

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/

Comment by makapuf 9 minutes ago

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.

Comment by jph 20 minutes ago

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.

Comment by kps 7 minutes ago

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

Comment by direwolf20 16 minutes ago

What is the purpose of making everything the same color?

Comment by Rygian 14 minutes ago

stdout and stderr get different colors.

Comment by j4cobgarby 2 hours 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.

Comment by BeetleB 1 hour ago

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

Comment by mrob 1 hour ago

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

Comment by kps 1 hour ago

>Every good terminal emulator lets you set custom palettes

Not differently for each program's output.

Comment by mrob 1 hour ago

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

Comment by sceptic123 53 minutes ago

unless you're colour blind

Comment by mrob 29 minutes ago

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.

Comment by skydhash 25 minutes ago

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

Comment by fassssst 52 minutes ago

Color is cultural. Red is associated with good in China

Comment by altcognito 40 minutes ago

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

Comment by red_admiral 1 hour ago

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

Comment by busterarm 2 hours 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.

Comment by Etheryte 1 hour 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 adding more mental overhead for the user, not less.

Comment by account42 1 hour ago

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.

Comment by makapuf 2 hours ago

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

Comment by xenophonf 1 hour 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.

Comment by makapuf 15 minutes ago

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 ?

Comment by craftkiller 1 hour ago

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

Comment by skydhash 2 hours 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.

Comment by tczMUFlmoNk 2 hours 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.

Comment by mrob 1 hour 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.

Comment by skydhash 1 hour 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.

Comment by jammcq 58 minutes ago

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.

Comment by bradrn 47 minutes ago

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

Comment by red_admiral 1 hour ago

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.

Comment by account42 1 hour ago

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.

Comment by thinking_cactus 32 minutes ago

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.

Comment by hnsmhthrow 31 minutes ago

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.

Comment by alias_neo 1 hour ago

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.

Comment by ori_b 25 minutes ago

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

https://no-color.org/

Comment by seanwilson 1 hour ago

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.

Comment by account42 1 hour ago

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

Comment by JoshTriplett 1 hour ago

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

Comment by takluyver 1 hour ago

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.

Comment by JoshTriplett 55 minutes ago

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.

Comment by alt187 1 hour ago

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.

Comment by sroussey 2 hours 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.

Comment by sroussey 1 hour 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/...

Comment by 2 hours ago

Comment by bitwize 1 hour 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.

Comment by xenophonf 2 hours 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.

Comment by davidw 14 minutes ago

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

Comment by skydhash 32 minutes ago

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.

Comment by maximgeorge 1 hour ago

[dead]

Comment by the_gipsy 2 hours ago

[flagged]

Comment by taswellian 2 hours ago

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

Comment by JoshTriplett 1 hour ago

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

Comment by Arch-TK 2 hours 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...

Comment by strogonoff 2 hours 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).

Comment by skydhash 2 hours 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.

Comment by keepamovin 1 hour ago

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.