aboutsummaryrefslogtreecommitdiff
path: root/src/cpt-lib
diff options
context:
space:
mode:
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 "$@"