How to choose colors for your CLI applications (2023)
71–80 of 103 posts
Re: How to choose colors for your CLI applications (2023)
#72I 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.
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 on your ADM3A, old timer? Our software is not for you."
Re: How to choose colors for your CLI applications (2023)
#73Earlier quoted context omitted.
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*.
Most of its successors are more like "shitty xterm emulators" whose conformance tests are "do my favorite mOdErN CLI apps work".
Re: How to choose colors for your CLI applications (2023)
#74If you're CLI application doesn't play nice with it (i haven't seen many) I don't use it.
Re: How to choose colors for your CLI applications (2023)
#75If you want a quick easy way to add some colors to your own shell scripts: export STDOUT_COLOR_START='[34m' export STDOUT_COLOR_STOP='[0m' export STDERR_COLOR_START='[31m' export STDERR_COLOR_STOP='[0m' 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"
declare GRN='\e[1;32m'
declare RED='\e[1;31m'
declare YLW='\e[1;33m'
declare CYN='\e[1;36m'
write_log() {
echo -e "[$( date +'%c' )] : ${1}\e[0m" | tee -a ${logfile}
}
write_log "${RED}I'm an ERROR"Re: How to choose colors for your CLI applications (2023)
#76As 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.
I want to be able to switch existing terminals with existing applications between themes.
Re: How to choose colors for your CLI applications (2023)
#77If you want a quick easy way to add some colors to your own shell scripts: export STDOUT_COLOR_START='[34m' export STDOUT_COLOR_STOP='[0m' export STDERR_COLOR_START='[31m' export STDERR_COLOR_STOP='[0m' 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…
declare STDOUT_COLOR='\e[34m'
declare STDERR_COLOR='\e[31m'
declare COLOR_STOP='\e[0m'
print_stdout() {
echo -e "${STDOUT_COLOR}${*}${COLOR_STOP}" &> /dev/stdout
}
print_stderrr() {
echo -e "${STDERR_COLOR}${*}${COLOR_STOP}" &> /dev/stderr
}
Like why are you exporting? Do you really need those in your environment?And those print statements aren't going to work by default.
Re: How to choose colors for your CLI applications (2023)
#78As 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.
For example like Mutt does: http://www.mutt.org/doc/manual/#color
Re: How to choose colors for your CLI applications (2023)
#79Earlier 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.
Globe key + E on Mac, Windows key + period on Windows, Ctrl + period on GNOME, Super key + period on KDE, yada yada.
Re: How to choose colors for your CLI applications (2023)
#80- 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://ratatui.rs and https://github.com/ratatui/ratatui
It's available from the usual places https://iterm2colorschemes.com/, https://windowsterminalthemes.dev/?theme=Aardvark%20Blue, built in to ghostty, extension for vscode etc.
[1]: https://github.com/mbadolato/iTerm2-Color-Schemes/pull/417