[pacman-dev] [PATCH 1/2] makepkg: define escape sequences globally

Cedric Staniewski cedric at gmx.ca
Fri Oct 23 07:51:26 EDT 2009


In doing so, it is possible to get rid of all the tests for colored
messages except for one global one.

Signed-off-by: Cedric Staniewski <cedric at gmx.ca>
---
 scripts/makepkg.sh.in |   42 +++++++++++++++---------------------------
 1 files changed, 15 insertions(+), 27 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 40367ae..2a3d22d 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -72,7 +72,6 @@ IGNOREARCH=0
 HOLDVER=0
 PKGFUNC=0
 SPLITPKG=0
-COLORMSG=0
 
 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
 # when dealing with svn/cvs/etc PKGBUILDs.
@@ -84,47 +83,27 @@ PACMAN_OPTS=
 
 plain() {
 	local mesg=$1; shift
-	if [ $COLORMSG -eq 1 ]; then
-		printf "\033[1;1m    ${mesg}\033[1;0m\n" "$@" >&2
-	else
-		printf "    ${mesg}\n" "$@" >&2
-	fi
+	printf "${BOLD}    ${mesg}${ALL_OFF}\n" "$@" >&2
 }
 
 msg() {
 	local mesg=$1; shift
-	if [ $COLORMSG -eq 1 ]; then
-		printf "\033[1;32m==>\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
-	else
-		printf "==> ${mesg}\n" "$@" >&2
-	fi
+	printf "${GREEN}==>${ALL_OFF_BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
 }
 
 msg2() {
 	local mesg=$1; shift
-	if [ $COLORMSG -eq 1 ]; then
-		printf "\033[1;34m  ->\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
-	else
-		printf "  -> ${mesg}\n" "$@" >&2
-	fi
+	printf "${BLUE}  ->${ALL_OFF_BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
 }
 
 warning() {
 	local mesg=$1; shift
-	if [ $COLORMSG -eq 1 ]; then
-		printf "\033[1;33m==> $(gettext "WARNING:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
-	else
-		printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
-	fi
+	printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF_BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
 }
 
 error() {
 	local mesg=$1; shift
-	if [ $COLORMSG -eq 1 ]; then
-		printf "\033[1;31m==> $(gettext "ERROR:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
-	else
-		printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
-	fi
+	printf "${RED}==> $(gettext "ERROR:")${ALL_OFF_BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
 }
 
 
@@ -1576,7 +1555,16 @@ fi
 
 # check if messages are to be printed using color
 if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
-	COLORMSG=1
+	readonly ALL_OFF="\033[1;0m" \
+						BOLD="\033[1;1m"
+	readonly ALL_OFF_BOLD="${ALL_OFF}${BOLD}" \
+						RED="${BOLD}\033[1;31m" \
+						BLUE="${BOLD}\033[1;34m" \
+						GREEN="${BOLD}\033[1;32m" \
+						YELLOW="${BOLD}\033[1;33m"
+else
+	unset ALL_OFF ALL_OFF_BOLD BOLD RED BLUE GREEN YELLOW
+	readonly ALL_OFF ALL_OFF_BOLD BOLD RED BLUE GREEN YELLOW
 fi
 
 # override settings with an environment variable for batch processing
-- 
1.6.5.1



More information about the pacman-dev mailing list