Live data from Hacker News

How to choose colors for your CLI applications (2023)

blog.xoria.org

51–60 of 103 posts

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

#52
post #35

Earlier quoted context omitted.

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

unless you're colour blind

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

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

#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:-}"
    }
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.

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

#54
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…

What is the purpose of making everything the same color?

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

#55
post #6

Earlier quoted context omitted.

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

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.

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 ?

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

#56

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.

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

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

#57
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…

What is the purpose of making everything the same color?

stdout and stderr get different colors.

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

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

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

#59
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…

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

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

#60
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".
Post reply on HN