contrib: Make pacdiff colors the same as makepkg

Added an `ask` message function that emulates pacman's appearance.

Signed-off-by: William Giokas <1007380@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
William Giokas 2013-03-04 02:42:34 -06:00 committed by Allan McRae
parent 5a67eee78c
commit f8ed8620d0
2 changed files with 14 additions and 26 deletions

View File

@ -24,22 +24,11 @@ declare -r myver='@PACKAGE_VERSION@'
diffprog=${DIFFPROG:-vimdiff} diffprog=${DIFFPROG:-vimdiff}
diffsearchpath=${DIFFSEARCHPATH:-/etc} diffsearchpath=${DIFFSEARCHPATH:-/etc}
locate=0 locate=0
USE_COLOR='y'
if tput setaf 0 &>/dev/null; then m4_include(../scripts/library/output_format.sh)
ALL_OFF="$(tput sgr0)"
BOLD="$(tput bold)" m4_include(../scripts/library/term_colors.sh)
BLUE="${BOLD}$(tput setaf 4)"
GREEN="${BOLD}$(tput setaf 2)"
YELLOW="${BOLD}$(tput setaf 3)"
PURPLE="${BOLD}$(tput setaf 5)"
else
ALL_OFF="\e[1;0m"
BOLD="\e[1;1m"
BLUE="${BOLD}\e[1;34m"
GREEN="${BOLD}\e[1;32m"
YELLOW="${BOLD}\e[1;33m"
PURPLE="${BOLD}\e[1;35m"
fi
usage() { usage() {
echo "$myname : a simple pacnew/pacorig/pacsave updater" echo "$myname : a simple pacnew/pacorig/pacsave updater"
@ -82,24 +71,18 @@ while IFS= read -u 3 -r -d '' pacfile; do
file="${pacfile%.pac*}" file="${pacfile%.pac*}"
file_type="pac${pacfile##*.pac}" file_type="pac${pacfile##*.pac}"
case $file_type in msg "%s file found for %s" "$file_type" "$file"
pacnew) printf "$GREEN%s$ALL_OFF" "$file_type";;
pacorig) printf "$YELLOW%s$ALL_OFF" "$file_type";;
pacsave) printf "$BLUE%s$ALL_OFF" "$file_type";;
esac
printf " file found for $PURPLE%s$ALL_OFF\n" "$file"
if [ ! -f "$file" ]; then if [ ! -f "$file" ]; then
echo " $file does not exist" warning "$file does not exist"
rm -iv "$pacfile" rm -iv "$pacfile"
continue continue
fi fi
if cmp -s "$pacfile" "$file"; then if cmp -s "$pacfile" "$file"; then
echo " Files are identical, removing..." msg2 "Files are identical, removing..."
rm -v "$pacfile" rm -v "$pacfile"
else else
printf " (V)iew, (S)kip, (R)emove %s, (O)verwrite with %s: [v/s/r/o] " "$file_type" "$file_type" ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s: [v/s/r/o] " "$file_type" "$file_type"
while read c; do while read c; do
case $c in case $c in
r|R) rm -v "$pacfile"; break ;; r|R) rm -v "$pacfile"; break ;;
@ -108,7 +91,7 @@ while IFS= read -u 3 -r -d '' pacfile; do
$diffprog "$pacfile" "$file" $diffprog "$pacfile" "$file"
rm -iv "$pacfile"; break ;; rm -iv "$pacfile"; break ;;
s|S) break ;; s|S) break ;;
*) printf " Invalid answer. Try again: [v/s/r/o] "; continue ;; *) ask "Invalid answer. Try again: [v/s/r/o] "; continue ;;
esac esac
done done
fi fi

View File

@ -16,6 +16,11 @@ msg2() {
printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1
} }
ask() {
local mesg=$1; shift
printf "${BLUE}::${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}" "$@" >&1
}
warning() { warning() {
local mesg=$1; shift local mesg=$1; shift
printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2