Support colorful output.

This commit is contained in:
Michał Górny 2010-07-12 11:27:40 +02:00
parent cdc95c4595
commit b4454e4e95

View File

@ -9,12 +9,12 @@ say() {
} }
die() { die() {
say "${@}" say "${RED}${@}${RESET}"
exit 1 exit 1
} }
sayv() { sayv() {
[ -n "${SC_VERBOSE}" ] && say "${@}" [ -n "${SC_VERBOSE}" ] && say "${GREEN}${@}${RESET}"
} }
req() { req() {
@ -112,13 +112,14 @@ Options:
-V, --version print version string, -V, --version print version string,
-c, --changelog backwards compat (ignored), -c, --changelog backwards compat (ignored),
-C, --nocolor disable colorful output,
-v, --verbose enable verbose output. -v, --verbose enable verbose output.
_EOH_ _EOH_
} }
# Guess what! # Guess what!
main() { main() {
local commitmsg local commitmsg monochrome
unset SC_VERBOSE unset SC_VERBOSE
while [ ${#} -gt 0 ]; do while [ ${#} -gt 0 ]; do
@ -135,6 +136,9 @@ main() {
-c|--changelog) -c|--changelog)
# Now changelog entries are implicit -- backwards compat. # Now changelog entries are implicit -- backwards compat.
;; ;;
-C|--nocolor)
monochrome=1
;;
-v|--verbose) -v|--verbose)
SC_VERBOSE=1 SC_VERBOSE=1
;; ;;
@ -151,6 +155,25 @@ main() {
shift shift
done done
if [ -n "${monochrome}" ]; then
RESET=
RED=
GREEN=
BGREEN=
YELLOW=
WHITE=
else
local esc
esc=$(printf '\033[')
RESET=${esc}0m
RED="${esc}1;31m"
GREEN=${esc}32m
BGREEN="${esc}1;32m"
YELLOW="${esc}1;33m"
WHITE="${esc}1;37m"
fi
[ -n "${commitmsg}" ] || die 'No commit message provided.' [ -n "${commitmsg}" ] || die 'No commit message provided.'
find_repo find_repo
@ -178,11 +201,12 @@ main() {
if [ -n "${bns}" ]; then if [ -n "${bns}" ]; then
echo echo
local bn local bn cbn
for bn in ${bns}; do for bn in ${bns}; do
cbn=#${WHITE}${bn}${NORMAL}
wget -q http://bugs.gentoo.org/show_bug.cgi?id=${bn} -O - \ wget -q http://bugs.gentoo.org/show_bug.cgi?id=${bn} -O - \
| sed -e 's; *<title>Gentoo Bug \([0-9]*\) - \(.*\)</title>;Bug \1: \2;p' \ | sed -e "s, *<title>Gentoo Bug \([0-9]*\) - \(.*\)</title>,Bug ${cbn}: ${BGREEN}\2${RESET},p" \
-e "s; *<title>Gentoo \(Invalid Bug ID\)</title>;Bug ${bn}: !! \1;p" -e d -e "s, *<title>Gentoo \(Invalid Bug ID\)</title>,Bug ${cbn}: ${YELLOW}!! \1${RESET},p" -e d
done done
echo echo
fi fi
@ -197,14 +221,15 @@ main() {
if [ $? -eq 2 ]; then if [ $? -eq 2 ]; then
old_repoman= old_repoman=
say 'Please update portage to newer version in order to have repoman supporting' say "${GREEN}Please update portage to newer version in order to have repoman supporting"
say "--ask option and thus delay the following question until after 'repoman full'." say "--ask option and thus delay the following question until after 'repoman full'.${RESET}"
say say
while true; do while true; do
local answ local answ
printf '%s' 'Commit changes? [Yes/No] ' >&2 printf '%s' "${WHITE}Commit changes?${RESET} [${BGREEN}Yes${RESET}/${RED}No${RESET}] ${GREEN}" >&2
read answ read answ
printf '%s' "${RESET}"
case "${answ}" in case "${answ}" in
[yY]|[yY][eE]|[yY][eE][sS]) [yY]|[yY][eE]|[yY][eE][sS])