[pacman-dev] [PATCH 1/3] makepkg: fallback to legacy termcap capabilities

Carlos Diaz 839273 at gmail.com
Thu Oct 14 12:32:45 EDT 2010


In some systems, such as Freebsd, the base tput isn't linked against a
terminfo capable ncurses.

This means that there's no portable way to set color, so instead of
guessing, makepkg fallbacks on using legacy termcap output manipulation.

For reference, see terminfo(5) and termcap(5) for a comparison between
the abilities.

The hardcoded list of terminals is taken from freebsdports/shells/tcshrc
and tmux [1]. This prevents echoing gibberish in dumb and otherwise
incapacitated terminals.

1:
http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/tmux/tty.c?rev=1.91;content-type=text%2Fplain

Signed-off-by: Carlos Diaz <839273 at gmail.com>
---
 scripts/makepkg.sh.in |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index bdf63ef..3d29d26 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1660,21 +1660,30 @@ PACMAN=${PACMAN:-pacman}
 # check if messages are to be printed using color
 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
 if [[ -t 2 && ! $USE_COLOR = "n" && $(check_buildenv color) = "y" ]]; then
-	# prefer terminal safe colored and bold text when tput is supported
 	if tput setaf 0 &>/dev/null; then
+		# tput linked against a compliant terminfo ncurses
 		ALL_OFF="$(tput sgr0)"
 		BOLD="$(tput bold)"
 		BLUE="${BOLD}$(tput setaf 4)"
 		GREEN="${BOLD}$(tput setaf 2)"
 		RED="${BOLD}$(tput setaf 1)"
 		YELLOW="${BOLD}$(tput setaf 3)"
-	else
+	elif [[ $TERM =~  ^(dtterm|rxvt|screen|xterm) ]]; then
+		# no terminfo, but don't fallback to ugly reverse text just yet
 		ALL_OFF="\033[1;0m"
 		BOLD="\033[1;1m"
 		BLUE="${BOLD}\033[1;34m"
 		GREEN="${BOLD}\033[1;32m"
 		RED="${BOLD}\033[1;31m"
 		YELLOW="${BOLD}\033[1;33m"
+	elif tput me &>/dev/null; then
+		# rely on termcap capabilities; no portable way of using color
+		ALL_OFF="$(tput me)"
+		BOLD="$(tput md)"
+		BLUE="$(tput mr)"    # reverse
+		GREEN="$(tput us)"   # underline
+		RED="$(tput so)"     # standout
+		YELLOW="$(tput mh)"  # half-bright
 	fi
 fi
 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
-- 
1.7.3.1



More information about the pacman-dev mailing list