Live data from Hacker News

How to choose colors for your CLI applications (2023)

blog.xoria.org

61–70 of 103 posts

Re: How to choose colors for your CLI applications (2023)

#61
post #39

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.

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

Re: How to choose colors for your CLI applications (2023)

#63

Earlier quoted context omitted.

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.

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.

Huh, indeed. I still can't find much information about this, but this page is very informative: https://jwodder.github.io/kbits/posts/term-fgbg/

Re: How to choose colors for your CLI applications (2023)

#64

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.

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.

And not everything that calls itself xterm-256color is actually xterm compatible *cough* GNOME *cough*.

Re: How to choose colors for your CLI applications (2023)

#66
post #39

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.

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

> constraining to invert is not sufficient in my opinion

Eh. Doing green/red text color with default background, maybe inverted works amazing for me. In fact, I'd say that every sensible colour scheme for a terminal should have as the default foreground/background colours something that is more or less contrasting against every other explicitly named colour, including black and white (I personally have #212121 on #EEEEEE).

Re: How to choose colors for your CLI applications (2023)

#67
I’ve bounced off of LazyGit multiple times because I never figured out how to make it play nice with a light theme terminal.

I haven’t used dark mode anything for years. I set my monitor so it’s roughly as bright, or slightly brighter than, a piece of white paper.

No more flash-bangs when some website doesn’t support dark mode.

Re: How to choose colors for your CLI applications (2023)

#68
post #53

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:-}" } Sou…

If you're writing a zsh script and not worried about portability, you can also use the prompt expansion colors with "print".

    print_color () {
      print -P "%F{$1}$2%f"
    }
And then to use it

   print_color "green" "This is printed in green"

Re: How to choose colors for your CLI applications (2023)

#69
post #68
post #53

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:-}" } Sou…

If you're writing a zsh script and not worried about portability, you can also use the prompt expansion colors with "print". print_color () { print -P "%F{$1}$2%f" } And then to use it print_color "green" "This is printed in green"

Nice. I put this in my .zshrc.

Re: How to choose colors for your CLI applications (2023)

#70
post #35
post #33

Earlier quoted context omitted.

>Every good terminal emulator lets you set custom palettes Not differently for each program's output .

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

If for something unrelated to good/bad looks good, I'm using red. Ditto for green.

Sure, if it was a status indicator and I used red for "good", I can see the point. But over the last few years I've had too many people tell me "Don't use red, people will think something is wrong" for things not semantically tied to good/bad.

People wear red clothes. They buy red cars. They eat red food. They date red heads. Red is OK.

Post reply on HN