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() {
say "${@}"
say "${RED}${@}${RESET}"
exit 1
}
sayv() {
[ -n "${SC_VERBOSE}" ] && say "${@}"
[ -n "${SC_VERBOSE}" ] && say "${GREEN}${@}${RESET}"
}
req() {
@ -112,13 +112,14 @@ Options:
-V, --version print version string,
-c, --changelog backwards compat (ignored),
-C, --nocolor disable colorful output,
-v, --verbose enable verbose output.
_EOH_
}
# Guess what!
main() {
local commitmsg
local commitmsg monochrome
unset SC_VERBOSE
while [ ${#} -gt 0 ]; do
@ -135,6 +136,9 @@ main() {
-c|--changelog)
# Now changelog entries are implicit -- backwards compat.
;;
-C|--nocolor)
monochrome=1
;;
-v|--verbose)
SC_VERBOSE=1
;;
@ -151,6 +155,25 @@ main() {
shift
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.'
find_repo
@ -178,11 +201,12 @@ main() {
if [ -n "${bns}" ]; then
echo
local bn
local bn cbn
for bn in ${bns}; do
cbn=#${WHITE}${bn}${NORMAL}
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' \
-e "s; *<title>Gentoo \(Invalid Bug ID\)</title>;Bug ${bn}: !! \1;p" -e d
| sed -e "s, *<title>Gentoo Bug \([0-9]*\) - \(.*\)</title>,Bug ${cbn}: ${BGREEN}\2${RESET},p" \
-e "s, *<title>Gentoo \(Invalid Bug ID\)</title>,Bug ${cbn}: ${YELLOW}!! \1${RESET},p" -e d
done
echo
fi
@ -197,14 +221,15 @@ main() {
if [ $? -eq 2 ]; then
old_repoman=
say '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 "${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'.${RESET}"
say
while true; do
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
printf '%s' "${RESET}"
case "${answ}" in
[yY]|[yY][eE]|[yY][eE][sS])