aboutsummaryrefslogtreecommitdiff
path: root/src/cpt-lib
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2020-09-05 09:51:19 +0000
committermerakor <cem@ckyln.com>2020-09-05 09:51:19 +0000
commitfb59a3a43cd81f3da5492cb2e6f51ee77f8b6204 (patch)
tree101408a67b6e4c1d32b0da5dce27a7d26cff0c97 /src/cpt-lib
parent5416e51a84066536701d503163512c2f5616d23b (diff)
downloadcpt-fb59a3a43cd81f3da5492cb2e6f51ee77f8b6204.tar.gz
cpt: add back support for setting colors, fix shellcheck error
FossilOrigin-Name: 4353efa436df913e647c5b43c709833fb76d12fb52d9db1b9bbaff04e55d0abf
Diffstat (limited to 'src/cpt-lib')
-rw-r--r--src/cpt-lib15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/cpt-lib b/src/cpt-lib
index 6957841..38e57c1 100644
--- a/src/cpt-lib
+++ b/src/cpt-lib
@@ -23,12 +23,10 @@ log() {
# All messages are printed to stderr to allow the user to hide build
# output which is the only thing printed to stdout.
#
- # '\033[1;32m' Set text to color '2' and make it bold.
- # '\033[m': Reset text formatting.
# '${3:-->}': If the 3rd argument is missing, set prefix to '->'.
- # '${2:+\033[1;3Xm}': If the 2nd argument exists, set text style of '$1'.
- printf '\033[1;33m%s \033[m%b%s\033[m %s\n' \
- "${3:-->}" "${2:+"\033[1;36m"}" "$1" "$2" >&2
+ # '${2:+colorb}': If the 2nd argument exists, set text style of '$1'.
+ printf '%b%s %b%b%s%b %s\n' \
+ "$colory" "${3:-->}" "$colre" "${2:+$colorb}" "$1" "$colre" "$2" >&2
}
die() {
@@ -1825,6 +1823,13 @@ main() {
# Set a value for CPT_COMPRESS if it isn't set.
: "${CPT_COMPRESS:=gz}"
+ # Unless being piped or the user specifically doesn't want colors, set
+ # colors. This can of course be overriden if the user specifically want
+ # colors during piping.
+ if { [ "$CPT_COLOR" != 0 ] && [ -t 1 ] ;} || [ "$CPT_COLOR" = 1 ]; then
+ colory="\033[1;33m" colorb="\033[1;36m" colre="\033[m"
+ fi
+
}
main "$@"