diff --git a/ChangeLog b/ChangeLog index a2eb4ca..31061a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,11 @@ Changes in version 1.14.2 * autospec - Davide Madrisan: Send the debug message showing autospec version as soon as possible. ++ improvement + * autospec, plugins/*,lib/lib*.lib - Davide Madrisan: + A color scheme can be selected now by using the new command-line option + '--colorize-theme'. + ------------------------------------------------------------------------------- Changes in version 1.14.1 - _TO*Hacklab release diff --git a/autospec.in b/autospec.in index 899fed4..e359f8b 100644 --- a/autospec.in +++ b/autospec.in @@ -63,6 +63,7 @@ function autospec.usage() { -V, --version "$"Print version number, then exit"" -q, --quiet "$"Run in quiet mode"" -r, --colorize "$"Enable the colorized output"" + --colorize-theme "$"Select the theme to be used for the colorized output"" -D, --debug "$"Run in debugging mode (very verbose output)"" "$"Usage"": @@ -90,8 +91,29 @@ notify.disable_colors { echo "$me: "$"library not found"": @libdir@/libcfg.lib" 1>&2 exit 1; } -for arg in $@; do - case $arg in +# Little helper function for reading args from the commandline. +# it automatically handles -a b and -a=b variants, and returns 1 if +# we need to shift $3. +# see. /usr/sbin/mkinitrd (dracut-024) +function read_arg() { + # $1 = arg name + # $2 = arg value + # $3 = arg parameter + local rematch='^[^=]*=(.*)$' + if [[ $2 =~ $rematch ]]; then + read "$1" <<< "${BASH_REMATCH[1]}" + elif [[ $3 != -* ]]; then + # Only read next arg if it not an arg itself. + read "$1" <<< "$3" + # There is no way to shift our callers args, so + # return 1 to indicate they should do it instead. + return 1 + fi +} + +args=($@) +while (($# > 0)); do + case ${1%%=*} in -u|--update) let "pck_update = 1" ;; -s|--source) @@ -106,15 +128,19 @@ for arg in $@; do let "verbose = 0" ;; -r|--colorize) let "colorize = 1" ;; + --colorize-theme) + read_arg colorize_theme "$@" || shift ;; -h|--help) let "print_help = 1" ;; -V|--version) let "print_version = 1" ;; *) ;; esac + shift done notify.debug "[${me[0]}, "$"version"" ${me[1]}]" +notify.debug "colorize_theme = \"$colorize_theme\"" case "$(( $pck_update + $spec_create + $pck_extract + $config_getvar ))" in 0) [ "$print_help" = "1" ] && autospec.usage 0 @@ -157,9 +183,8 @@ notify.debug "tmpargfile = \`${NOTE}$tmpargfile${NORM}'" # workaround to bypass the issues related to bash expansion in multi-word # strings (ex: autospec -u s.spec -a4 1.0 --changelog "here's the problem") echo -n "set -- " > $tmpargfile -while [ $# -gt 0 ]; do - echo -n "\"$1\" " >> $tmpargfile - shift +for i in `seq 1 1 ${#args[@]}`; do + echo -n "\"${args[$i-1]}\" " >> $tmpargfile done echo >> $tmpargfile diff --git a/lib/libmsgmng.lib.in b/lib/libmsgmng.lib.in index 40a61bb..694b217 100644 --- a/lib/libmsgmng.lib.in +++ b/lib/libmsgmng.lib.in @@ -14,31 +14,6 @@ if [[ -z "$LANG" && -r /etc/sysconfig/i18n ]]; then fi TEXTDOMAIN="libmsgmng"; export TEXTDOMAIN -# function notify.enable_colors -# enable if possible the colorized output -# args: -# none -function notify.enable_colors() { - if [[ -t 1 && "$TERM" != raw && "$TERM" != dumb ]]; then - ESC=$(echo -en "\033") # ascii ESCape - [ "$CRIT" ] || CRIT="${ESC}[1;31m" # switch on red - [ "$NOTE" ] || NOTE="${ESC}[1;33m" # switch on yellow - [ "$WARN" ] || WARN="${ESC}[1;31m" - [ "$EXIT" ] || EXIT="${ESC}[1;31m" - [ "$NORM" ] || NORM=$(echo -en "${ESC}[m\017") - else - ESC= CRIT= NOTE= WARN= EXIT= NORM= - fi -} - -# function notify.disable_colors -# disable the colorized output -# args: -# none -function notify.disable_colors() { - ESC= CRIT= NOTE= WARN= EXIT= NORM= -} - # notify family of message handling functions: # - notify.warning # - notify.error @@ -73,4 +48,59 @@ function notify.note() { echo -e "${1:-$notify_def_msg}" } +# function notify.enable_colors +# enable if possible the colorized output +# args: +# none +function notify.enable_colors() { + local colorize_theme="$1" + # for backward compatibility + [ "$colorize_theme" ] || colorize_theme="terminal-dark" + + case "$colorize_theme" in + "web") + CRIT="" + NOTE="" + WARN="" + EXIT="$CRIT" + NORM="" + ;; + "terminal-white") + if [[ -t 1 && "$TERM" != raw && "$TERM" != dumb ]]; then + ESC=$(echo -en "\033") # ascii ESCape + [ "$NOTE" ] || NOTE="${ESC}[1;34m" # switch on blu + [ "$WARN" ] || WARN="${ESC}[1;31m" + [ "$EXIT" ] || EXIT="${ESC}[1;31m" + [ "$NORM" ] || NORM=$(echo -en "${ESC}[m\017") + else + ESC= CRIT= NOTE= WARN= EXIT= NORM= + fi + ;; + "terminal-dark") + if [[ -t 1 && "$TERM" != raw && "$TERM" != dumb ]]; then + ESC=$(echo -en "\033") # ascii ESCape + [ "$CRIT" ] || CRIT="${ESC}[1;31m" # switch on red + [ "$NOTE" ] || NOTE="${ESC}[1;33m" # switch on yellow + [ "$WARN" ] || WARN="${ESC}[1;31m" + [ "$EXIT" ] || EXIT="${ESC}[1;31m" + [ "$NORM" ] || NORM=$(echo -en "${ESC}[m\017") + else + ESC= CRIT= NOTE= WARN= EXIT= NORM= + fi + ;; + *) echo \ +$"unknown color theme \`$colorize_theme': colors will be disabled" + ESC= CRIT= NOTE= WARN= EXIT= NORM= + ;; + esac +} + +# function notify.disable_colors +# disable the colorized output +# args: +# none +function notify.disable_colors() { + ESC= CRIT= NOTE= WARN= EXIT= NORM= +} + } # endif $libmsgmng_is_loaded diff --git a/plugins/config-getvar.in b/plugins/config-getvar.in index 720ee4e..f7259a6 100644 --- a/plugins/config-getvar.in +++ b/plugins/config-getvar.in @@ -64,6 +64,7 @@ function usage() { -V, --version "$"Print version number, then exit"" -q, --quiet "$"Run in quiet mode"" -r, --colorize "$"Enable the colorized output"" + --colorize-theme "$"Select the theme to be used for the colorized output"" -D, --debug "$"Run in debugging mode (very verbose output)"" "$"Samples"": @@ -96,7 +97,7 @@ done exec_options=`LC_ALL=C getopt \ -o C:DqrhV \ --long eval:,config:,\ -debug,quiet,colorize,help,version,\ +debug,quiet,colorize,colorize-theme:,help,version,\ frontend_opts: \ -n "$me" -- "$@"` [ $? = 0 ] || exit 1 @@ -116,6 +117,8 @@ while :; do let "verbose = 0" ;; -r|--colorize) let "colorize = 1" ;; + --colorize-theme) + colorize_theme="$2"; shift ;; -h|--help) usage 0 ;; -V|--version) @@ -131,7 +134,8 @@ for arg in $@; do notify.error $"unrecognized option"" -- \`$arg'" done -[ "$colorize" = "1" ] && notify.enable_colors || notify.disable_colors +[ "$colorize" = "1" ] && notify.enable_colors "$colorize_theme" \ + || notify.disable_colors # config.getvar() # Parameters: diff --git a/plugins/pck-extract.in b/plugins/pck-extract.in index 2748b9f..e2cc0b8 100644 --- a/plugins/pck-extract.in +++ b/plugins/pck-extract.in @@ -68,6 +68,7 @@ function usage() { -V, --version "$"Print version number, then exit"" -q, --quiet "$"Run in quiet mode"" -r, --colorize "$"Enable the colorized output"" + --colorize-theme "$"Select the theme to be used for the colorized output"" -D, --debug "$"Run in debugging mode (very verbose output)"" "$"Samples"": @@ -101,7 +102,7 @@ exec_options=`LC_ALL=C getopt \ -o xF:DqrhV \ --long \ extract,files:,destdir:,\ -debug,quiet,colorize,help,version,\ +debug,quiet,colorize,colorize-theme:,help,version,\ frontend_opts: \ -n "$me" -- "$@"` [ $? = 0 ] || exit 1 @@ -122,6 +123,8 @@ while :; do let "verbose = 0" ;; -r|--colorize) let "colorize = 1" ;; + --colorize-theme) + colorize_theme="$2"; shift ;; -h|--help) usage 0 ;; -V|--version) @@ -137,7 +140,8 @@ for arg in $@; do notify.error $"unrecognized option"" -- \`$arg'" done -[ "$colorize" = "1" ] && notify.enable_colors || notify.disable_colors +[ "$colorize" = "1" ] && notify.enable_colors "$colorize_theme" \ + || notify.disable_colors # s_rpm_pck : the name of the srpm package (local or remote) # (i.e. /usr/src/RPM/SRPMS/automake-1.9-1qilnx.src.rpm) diff --git a/plugins/pck-update.in b/plugins/pck-update.in index 5edd498..cfcd638 100644 --- a/plugins/pck-update.in +++ b/plugins/pck-update.in @@ -154,6 +154,7 @@ function usage() { -V, --version "$"Print version number, then exit"" -q, --quiet "$"Run in quiet mode"" -r, --colorize "$"Enable the colorized output"" + --colorize-theme "$"Select the theme to be used for the colorized output"" -D, --debug "$"Run in debugging mode (very verbose output)"" "$"Samples"": @@ -196,7 +197,7 @@ server-download:,server-upload:,server:,\ changelog:,nosrpm,norpm,list-check,update-autobuildreq,\ force-update,force-build,force-install,force-download,force,\ ignore-test:,clear,format,log,rebuild,root:,\ -debug,quiet,colorize,help,version,\ +debug,quiet,colorize,colorize-theme:,help,version,\ frontend_opts: \ -n "$me" -- "$@"` [ $? = 0 ] || exit 1 @@ -278,6 +279,8 @@ while :; do let "verbose = 0" ;; -r|--colorize) let "colorize = 1" ;; + --colorize-theme) + colorize_theme="$2"; shift ;; -h|--help) usage 0 ;; -V|--version) @@ -310,7 +313,9 @@ fi [ "$logging" = "1" ] && let "colorize = 0" -[ "$colorize" = "1" ] && notify.enable_colors || notify.disable_colors +[ "$colorize" = "1" ] && notify.enable_colors "$colorize_theme" \ + || notify.disable_colors + # default values for non mandatory configuration variables [ "$logging_dir" ] || logging_dir="${tmppath_dir:-/var/tmp}/@package@" diff --git a/plugins/spec-create.in b/plugins/spec-create.in index f6b90f7..8e1b588 100644 --- a/plugins/spec-create.in +++ b/plugins/spec-create.in @@ -121,6 +121,7 @@ function usage() { -V, --version "$"Print version number, then exit"" -q, --quiet "$"Run in quiet mode"" -r, --colorize "$"Enable the colorized output"" + --colorize-theme "$"Select the theme to be used for the colorized output"" -D, --debug "$"Run in debugging mode (very verbose output)"" "$"Samples"": @@ -162,7 +163,7 @@ exec_options=`LC_ALL=C getopt \ --long \ source:,pck-name:,pck-version:,type:,output:,changelog:,\ git-branch:,preserve-dot-git,\ -debug,quiet,colorize,help,version,\ +debug,quiet,colorize,colorize-theme:,help,version,\ frontend_opts: \ -n "$me" -- "$@"` [ $? = 0 ] || exit 1 @@ -197,6 +198,8 @@ while :; do let "verbose = 0" ;; -r|--colorize) let "colorize = 1" ;; + --colorize-theme) + colorize_theme="$2"; shift ;; -h|--help) usage 0 ;; -V|--version) @@ -207,7 +210,8 @@ while :; do shift done -[ "$colorize" = "1" ] && notify.enable_colors || notify.disable_colors +[ "$colorize" = "1" ] && notify.enable_colors "$colorize_theme" \ + || notify.disable_colors for arg in $@; do notify.error $"unrecognized option"" -- \`$arg'" diff --git a/po/it/autospec_fe.po b/po/it/autospec_fe.po index 3533f8d..68a875f 100644 --- a/po/it/autospec_fe.po +++ b/po/it/autospec_fe.po @@ -58,6 +58,9 @@ msgstr "Non stampa alcun dettaglio delle operazioni in esecuzione" msgid "Enable the colorized output" msgstr "Abilita l'output colorato" +msgid "Select the theme to be used for the colorized output" +msgstr "Seleziona il tema da usare per generare l'output colorato" + msgid "Run in debugging mode (very verbose output)" msgstr "Attiva la modalità di debugging (output prolisso)" diff --git a/po/it/config-getvar.po b/po/it/config-getvar.po index e21d2c8..3fb904c 100644 --- a/po/it/config-getvar.po +++ b/po/it/config-getvar.po @@ -69,6 +69,9 @@ msgstr "Non stampa alcun dettaglio delle operazioni in esecuzione" msgid "Enable the colorized output" msgstr "Abilita l'output colorato" +msgid "Select the theme to be used for the colorized output" +msgstr "Seleziona il tema da usare per generare l'output colorato" + msgid "Run in debugging mode (very verbose output)" msgstr "Attiva la modalità di debugging (output prolisso)" diff --git a/po/it/libmsgmng.po b/po/it/libmsgmng.po index 578d193..3822643 100644 --- a/po/it/libmsgmng.po +++ b/po/it/libmsgmng.po @@ -21,3 +21,6 @@ msgstr "questo script richiede bash versione 2 o superiore" msgid "no message" msgstr "nessun messaggio" + +msgid "unknown color theme \\`\\$colorize_theme': colors will be disabled" +msgstr "tema di colori sconosciuto \\`\\$colorize_theme': output con colori disabilitato" diff --git a/po/it/pck-extract.po b/po/it/pck-extract.po index c02b961..4f60684 100644 --- a/po/it/pck-extract.po +++ b/po/it/pck-extract.po @@ -66,6 +66,9 @@ msgstr "Non stampa alcun dettaglio delle operazioni in esecuzione" msgid "Enable the colorized output" msgstr "Abilita l'output colorato" +msgid "Select the theme to be used for the colorized output" +msgstr "Seleziona il tema da usare per generare l'output colorato" + msgid "Run in debugging mode (very verbose output)" msgstr "Attiva la modalità di debugging (output prolisso)" diff --git a/po/it/pck-update.po b/po/it/pck-update.po index 6cc816d..1f49b14 100644 --- a/po/it/pck-update.po +++ b/po/it/pck-update.po @@ -183,6 +183,9 @@ msgstr "Non stampa alcun dettaglio delle operazioni in esecuzione" msgid "Enable the colorized output" msgstr "Abilita l'output colorato" +msgid "Select the theme to be used for the colorized output" +msgstr "Seleziona il tema da usare per generare l'output colorato" + msgid "Run in debugging mode (very verbose output)" msgstr "Attiva la modalità di debugging (output prolisso)" diff --git a/po/it/spec-create.po b/po/it/spec-create.po index 1c14266..2343ea2 100644 --- a/po/it/spec-create.po +++ b/po/it/spec-create.po @@ -103,6 +103,9 @@ msgstr "Non stampa alcun dettaglio delle operazioni in esecuzione" msgid "Enable the colorized output" msgstr "Abilita l'output colorato" +msgid "Select the theme to be used for the colorized output" +msgstr "Seleziona il tema da usare per generare l'output colorato" + msgid "Run in debugging mode (very verbose output)" msgstr "Attiva la modalità di debugging (output prolisso)"