commit 1e431573b18ef38f54c65c4a143a4aa29c1e3e6a from: Sergey Bronnikov date: Mon Jul 08 11:42:07 2024 UTC litclock: support NO_COLOR The patch brings support of `NO_COLOR` [1] environment variable. `litclock` will not use coloring when `NO_COLOR` is not empty. 1. http://no-color.org/ commit - 90294e6f4d90527c408f8d7a7071c0394e5c5c98 commit + 1e431573b18ef38f54c65c4a143a4aa29c1e3e6a blob - 3d6fdf18c7ecda9f2efaee03ae0ebd3ba6a69f0a blob + b520a2f387bc69669508257f5c983e11b64822d0 --- CHANGELOG.md +++ CHANGELOG.md @@ -8,6 +8,7 @@ change log follows the conventions of ### Added +- Support `NO_COLOR` in `litclock`. - Option for generating video files. - Option for setting a language in a build script. blob - d210147a3275238fb42327331d298c88e08471fb blob + 41d127177f1ff8bb1be4533c9a7cfb5975c5c5f6 --- litclock +++ litclock @@ -1,8 +1,8 @@ #!/usr/bin/bash # -# litclock 0.1.0 -# Copyright (c) 2022, Sergey Bronnikov +# litclock 0.2.0 +# Copyright (c) 2022-2024, Sergey Bronnikov # https://github.com/ligurio/litclock # # litclock script is released under the BSD 2-Clause license. @@ -11,7 +11,7 @@ # SPDX-License-Identifier: BSD-2-Clause # -set -eu +set -e PREFIX_DATA="/usr/local/share" @@ -39,6 +39,21 @@ shift $((OPTIND-1)) quotes_file="${PREFIX_DATA}/litclock/quotes_${lang}.csv" +printf_color() { + local no_color_support="$NO_COLOR" + local fmt="$1" + local text="$2" + if [ -z "${no_color_support}" ]; then + printf "%b" "$DEFAULT_COLOR" + # shellcheck disable=SC2059 + # shellcheck disable=SC2086 + printf $fmt "$text" + printf "%b" "$DISABLE_COLOR" + else + printf "%s" "$time_words" + fi +} + if ! [ -f "$quotes_file" ]; then echo "File $quotes_file is not found." exit 1 @@ -65,9 +80,7 @@ do printf "\"" printf "%s" "$quote_first" - printf "%b" "$DEFAULT_COLOR" - printf "%s" "$time_words" - printf "%b" "$DISABLE_COLOR" + printf_color "%s" "$time_words" printf "%s" "$quote_last" printf "\"\n" printf " -- '%s', %s\n\n" "$title" "$author" blob - 65579eea5704afbb797320824bfcabe0d1156ef8 blob + 874a7600884918519dd33f4516e72e99cf3d3da2 --- litclock.1 +++ litclock.1 @@ -1,5 +1,5 @@ .\" -.\" Copyright (c) 2022-2023, Sergey Bronnikov +.\" Copyright (c) 2022-2024, Sergey Bronnikov .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -52,6 +52,10 @@ Specify a language. Possible values are "ru" and "en". Default language is "ru". .El +.Pp +By default litclock highlights a part of quote with time by red color. +With non-empty NO_COLOR +environment variable litclock will disable colored text output. .Sh EXAMPLES Display a quote for a current time: .Pp