[pacman-dev] [PATCH] Refactor testing for color message output
Allan McRae
allan at archlinux.org
Sat Mar 14 10:23:03 EDT 2009
Allan McRae wrote:
> Signed-off-by: Allan McRae <allan at archlinux.org>
> ---
> scripts/makepkg.sh.in | 16 +++++++++++-----
> 1 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
> index 3ff256f..d44fe0d 100644
> --- a/scripts/makepkg.sh.in
> +++ b/scripts/makepkg.sh.in
> @@ -69,6 +69,7 @@ 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.
> @@ -80,7 +81,7 @@ PACMAN_OPTS=
>
> plain() {
> local mesg=$1; shift
> - if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
> + if [ COLORMSG -eq 1 ]; then
> printf "\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
> else
> printf " ${mesg}\n" "$@" >&2
> @@ -89,7 +90,7 @@ plain() {
>
> msg() {
> local mesg=$1; shift
> - if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
> + 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
> @@ -98,7 +99,7 @@ msg() {
>
> msg2() {
> local mesg=$1; shift
> - if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
> + 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
> @@ -107,7 +108,7 @@ msg2() {
>
> warning() {
> local mesg=$1; shift
> - if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
> + 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
> @@ -116,7 +117,7 @@ warning() {
>
> error() {
> local mesg=$1; shift
> - if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
> + 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
> @@ -1303,6 +1304,11 @@ if [ ! $(type -t gettext) ]; then
> }
> fi
>
This is a stupid place to put this block... We haven't parsed options
so USE_COLOR is not set and we have not read makepkg.conf so
check_buildenv is useless.
I have moved it to after the sourcing of user-specific makepkg.conf
overrides on my working branch.
>
> +# check if messages are to be printed using color
> +if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
> + COLORMSG=1
> +fi
> +
> ARGLIST=$@
>
> # Parse Command Line Options.
>
More information about the pacman-dev
mailing list