commit 6a2e214158c5ae7d1b40c198ea62c31f333a1c2e parent c56a82c285b7bfc26a639ff0f06d3d955ad5dcc8 Author: phoebos <ben@bvnf.space> Date: Mon, 20 Jun 2022 01:25:01 +0100 uxnsolve: no colours if stdout is not a tty Diffstat:
M | uxnsolve | | | 12 | +++++++++--- |
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/uxnsolve b/uxnsolve @@ -19,13 +19,19 @@ case "$1" in ;; esac +[ -t 1 ] && { + red="\033[1;31m" + yellow="\033[1;33m" + reset="\033[m" +} + debug_file="$1" source_file="${1%.debug}" check_versions() { read -r v < "$1" if [ "$v" != "$VERSION" ]; then - printf "\033[1;33mERROR\033[m: incompatible version '%s' (this tool is version %d)\n" "$v" "$VERSION" >&2 + printf "${yellow}ERROR${reset}: incompatible version '%s' (this tool is version %d)\n" "$v" "$VERSION" >&2 exit 1 fi } @@ -34,7 +40,7 @@ compare_file_timestamps() { # TODO: recurse through included files to check timestamps case "$(ls -t "$1" "$1.debug")" in "$1.debug"*) ;; - *) printf "\033[1;33mWARNING\033[m: source file is newer than debug info\n" >&2 ;; + *) printf "${yellow}WARNING${reset}: source file is newer than debug info\n" >&2 ;; esac } @@ -68,7 +74,7 @@ print_highlighted() { j=1 for tok; do if [ "$j" -eq "$index" ]; then - printf " \033[1;31m%s\033[m" "$tok" + printf " ${red}%s${reset}" "$tok" else printf " %s" "$tok" fi