How to choose colors for your CLI applications (2023)
51–60 of 103 posts
Re: How to choose colors for your CLI applications (2023)
#52Re: How to choose colors for your CLI applications (2023)
#53 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:-}"
}
Source: https://github.com/sixarm/unix-shell-script-kitThe 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)
#54If 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…
Re: How to choose colors for your CLI applications (2023)
#55Earlier 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.
Re: How to choose colors for your CLI applications (2023)
#56I 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.
Re: How to choose colors for your CLI applications (2023)
#57If 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…
What is the purpose of making everything the same color?
Re: How to choose colors for your CLI applications (2023)
#58Re: How to choose colors for your CLI applications (2023)
#59If 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…
tty -s
2. Don't hardcode escape sequences. Use (e.g.) export STDOUT_COLOR_START="`tput setaf 4`".