Live data from Hacker News

How to choose colors for your CLI applications (2023)

blog.xoria.org

91–100 of 103 posts

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

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

In my experience with live codebases, "error" or "warning" rarely mean the same thing to the same person, but admittedly you're much more likely to guess that they're in use as opposed to crying-green-clown emoji

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

#93
post #51

As long as you respect the NO_COLOR variable, it will work for me. https://no-color.org/

That's a funny example. I have no issues with the idea of course but in my day to day life I'm way more likely to encounter an issue with colors being lost after sent to a pager or a log file or tee or what not

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

#94
post #81
post #80

I made the "Aardvark Blue" a while back[1] to solve some of the problems that most color schemes have. The goal of this theme is that: - colors are fairly natural - background and black are distinct - grays are naturally ordered avoiding full black - light and dark colors are distinct from each other - all colors look good on background, black, dark gray, gray, white We use this for all the screenshots on https://rat…

Funny thing, those are not "the usual places" I've ever heard of, and I care somewhat about color schemes. Each of us lives in our own bubble... (my bubble is not iterm2 and not windows)

iterm2colorschemes is a source for various other tools as it ports out to

"Terminal, Konsole, PuTTY, Xresources, XRDB, Remmina, Termite, XFCE, Tilda, FreeBSD VT, Terminator, Kitty, MobaXterm, LXTerminal, Microsoft's Windows Terminal, Visual Studio, Alacritty, Ghostty, and many more."

You may have used data from it without knowing about it.

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

#95
post #87

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.

Big blocks of text are difficult to parse

Not with sed and awk they aren't.

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

#96
post #72

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 agree. So many TUIs from webshit devs don't even bother to call isatty, let alone check terminfo to see if ANSI escape codes are even valid for this terminal. But modern open source subscribes to Mao's Continuous Revolution Theory. Calls for some measure of stability and sanity are usually dismissed with some form of the argument "awwww, is poor diddums afwaid of a widdle change?" Or in this case, "still using vi o…

Emacs on a Link MC5, although something doesn't like how the terminal handles flow control. I'm not sure if it's the O/S, the UART, the cable, or the terminal, but I have issues with I/O corruption. Even something a simple as a directory listing will get messed up, and on both FreeBSD and Linux, so maybe that rules out the O/S. Oh well. I'll figure it out some day.

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

#97
post #94
post #81

Earlier quoted context omitted.

Funny thing, those are not "the usual places" I've ever heard of, and I care somewhat about color schemes. Each of us lives in our own bubble... (my bubble is not iterm2 and not windows)

iterm2colorschemes is a source for various other tools as it ports out to "Terminal, Konsole, PuTTY, Xresources, XRDB, Remmina, Termite, XFCE, Tilda, FreeBSD VT, Terminator, Kitty, MobaXterm, LXTerminal, Microsoft's Windows Terminal, Visual Studio, Alacritty, Ghostty, and many more." You may have used data from it without knowing about it.

> You may have used data from it without knowing about it.

Plausible!

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

#98
post #97
post #94

Earlier quoted context omitted.

iterm2colorschemes is a source for various other tools as it ports out to "Terminal, Konsole, PuTTY, Xresources, XRDB, Remmina, Termite, XFCE, Tilda, FreeBSD VT, Terminator, Kitty, MobaXterm, LXTerminal, Microsoft's Windows Terminal, Visual Studio, Alacritty, Ghostty, and many more." You may have used data from it without knowing about it.

> You may have used data from it without knowing about it. Plausible!

Yeah, when I created that repo, it was for me to store iterm themes that I found, and it took off and got ports to, well, pretty much every terminal . I didn't want to rename the repo since it's linked to in so many places. The main link people usually see is iterm2colorschemes.com but I do own terminalthemes.com and should probably just get around to pointing that one to the repo, too

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

#99

Earlier quoted context omitted.

unless you're colour blind

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

> Red here does not mean #ff0000

For you maybe.

"Look it is not gray on gray is black #777777 on white #333333". /s

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

#100
post #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`".

Yes good points both, thank you. The source code link has more explanation about color choices and my preference of POSIX compatibility. You can also see the color function that checks NO_COLOR, CLICOLOR_FORCE, TERM = "dumb", -t 1, etc.

For color operands, I use raw escape codes because I aim for POSIX compatibility. If I'm working on something that needs more capabilities then I switch to a more powerful programming language e.g. python, rust, etc.

As far as I understand, POSIX tput defines some terminal operands (clear, init, reset, etc.) but not color operands (setaf, setab, sgr0, etc.).

Post reply on HN