support affichage actions

This commit is contained in:
Jephté Clain 2024-03-27 04:25:09 +04:00
parent 739aed8f5e
commit c470c00c34
4 changed files with 263 additions and 332 deletions

View File

@ -2,7 +2,7 @@
function __esection() {
local -a lines
local lsep prefix="$(__edate)${NULIB__TLEVEL}"
local lsep prefix="$(__edate)$(__eindent0)"
local length="${COLUMNS:-80}"
setx lsep=__complete "$prefix" "$length" -
@ -18,7 +18,7 @@ function __esection() {
}
function __etitle() {
local -a lines; local maxlen=0
local prefix="$(__edate)${NULIB__TLEVEL}"
local prefix="$(__edate)$(__eindent0)"
setx -a lines=echo "$1"
for line in "${lines[@]}"; do
@ -30,7 +30,7 @@ function __etitle() {
}
function __edesc() {
local -a lines
local prefix="$(__edate)${NULIB__TLEVEL}"
local prefix="$(__edate)$(__eindent0)"
setx -a lines=echo "$1"
for line in "${lines[@]}"; do
@ -39,7 +39,7 @@ function __edesc() {
}
function __ebanner() {
local -a lines
local lsep prefix="$(__edate)${NULIB__TLEVEL}"
local lsep prefix="$(__edate)$(__eindent0)"
local length="${COLUMNS:-80}"
setx lsep=__complete "$prefix" "$length" =
@ -52,30 +52,26 @@ function __ebanner() {
done
tooenc "$lsep$COULEUR_NORMALE"
}
function __eimportant() { tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_ROUGE}!${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __eattention() { tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_JAUNE}*${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __eerror() { tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_ROUGE}E${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __ewarn() { tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_JAUNE}W${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __enote() { tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_VERTE}N${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __einfo() { tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_BLEUE}I${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __edebug() { tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_BLANCHE}D${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __eimportant() { tooenc "$(__edate)$(__eindent0)${COULEUR_ROUGE}!${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __eattention() { tooenc "$(__edate)$(__eindent0)${COULEUR_JAUNE}*${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __eerror() { tooenc "$(__edate)$(__eindent0)${COULEUR_ROUGE}E${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __ewarn() { tooenc "$(__edate)$(__eindent0)${COULEUR_JAUNE}W${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __enote() { tooenc "$(__edate)$(__eindent0)${COULEUR_VERTE}N${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __einfo() { tooenc "$(__edate)$(__eindent0)${COULEUR_BLEUE}I${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __edebug() { tooenc "$(__edate)$(__eindent0)${COULEUR_BLANCHE}D${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __estep() { tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_BLANCHE}.${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __estepe() { tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_ROUGE}.${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __estepw() { tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_JAUNE}.${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __estepn() { tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_VERTE}.${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __estepi() { tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_BLEUE}.${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __estep_() { tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_BLANCHE}.${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __estepe_() { tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_ROUGE}.${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __estepw_() { tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_JAUNE}.${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __estepn_() { tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_VERTE}.${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __estepi_() { tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_BLEUE}.${COULEUR_NORMALE} $(__indent "$1" " ")"; }
function __estep() { tooenc "$(__edate)$(__eindent0)${COULEUR_BLANCHE}.${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __estepe() { tooenc "$(__edate)$(__eindent0)${COULEUR_ROUGE}.${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __estepw() { tooenc "$(__edate)$(__eindent0)${COULEUR_JAUNE}.${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __estepn() { tooenc "$(__edate)$(__eindent0)${COULEUR_VERTE}.${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __estepi() { tooenc "$(__edate)$(__eindent0)${COULEUR_BLEUE}.${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __estep_() { tooenc_ "$(__edate)$(__eindent0)${COULEUR_BLANCHE}.${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __estepe_() { tooenc_ "$(__edate)$(__eindent0)${COULEUR_ROUGE}.${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __estepw_() { tooenc_ "$(__edate)$(__eindent0)${COULEUR_JAUNE}.${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __estepn_() { tooenc_ "$(__edate)$(__eindent0)${COULEUR_VERTE}.${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __estepi_() { tooenc_ "$(__edate)$(__eindent0)${COULEUR_BLEUE}.${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __ebegin() { local p="." i=" "; tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_BLANCHE}.${COULEUR_NORMALE} $(__indent "$1" " "): "; }
function __edoto() { echo_ "."; }
function __edotw() { echo_ "${COULEUR_JAUNE}w${COULEUR_NORMALE}"; }
function __edotx() { echo_ "${COULEUR_ROUGE}x${COULEUR_NORMALE}"; }
function __edotp() { echo_ "${COULEUR_JAUNE}+${COULEUR_NORMALE}"; }
function __edotd() { tooenc "($1)"; }
function __eendo() { echo "${COULEUR_VERTE}[ok]${COULEUR_NORMALE}"; }
function __eendx() { echo "${COULEUR_ROUGE}[error]${COULEUR_NORMALE}"; }
function __action() { tooenc "$(__edate)$(__eindent0)${COULEUR_BLANCHE}.${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __asuccess() { tooenc "$(__edate)$(__eindent0)${COULEUR_VERTE}${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __afailure() { tooenc "$(__edate)$(__eindent0)${COULEUR_ROUGE}${COULEUR_NORMALE} $(__eindent "$1" " ")"; }
function __adone() { tooenc "$(__edate)$(__eindent0)$(__eindent "$1")"; }

View File

@ -2,7 +2,7 @@
function __esection() {
local -a lines
local lsep prefix="$(__edate)${NULIB__TLEVEL}"
local lsep prefix="$(__edate)$(__eindent0)"
local length="${COLUMNS:-80}"
setx lsep=__complete "$prefix" "$length" -
@ -18,15 +18,15 @@ function __esection() {
}
function __etitle() {
local p="TITLE: " i=" "
tooenc "$(__edate)${NULIB__TLEVEL}${p}$(__indent "$1" "$i")"
tooenc "$(__edate)$(__eindent0)${p}$(__eindent "$1" "$i")"
}
function __edesc() {
local p="DESC: " i=" "
tooenc "$(__edate)${NULIB__TLEVEL}${p}$(__indent "$1" "$i")"
tooenc "$(__edate)$(__eindent0)${p}$(__eindent "$1" "$i")"
}
function __ebanner() {
local -a lines
local lsep prefix="$(__edate)${NULIB__TLEVEL}"
local lsep prefix="$(__edate)$(__eindent0)"
local length="${COLUMNS:-80}"
setx lsep=__complete "$prefix" "$length" =
@ -39,32 +39,28 @@ function __ebanner() {
done
tooenc "$lsep"
}
function __eimportant() { tooenc "$(__edate)${NULIB__TLEVEL}IMPORTANT! $(__indent "$1" " ")"; }
function __eattention() { tooenc "$(__edate)${NULIB__TLEVEL}ATTENTION! $(__indent "$1" " ")"; }
function __eerror() { tooenc "$(__edate)${NULIB__TLEVEL}ERROR: $(__indent "$1" " ")"; }
function __ewarn() { tooenc "$(__edate)${NULIB__TLEVEL}WARNING: $(__indent "$1" " ")"; }
function __enote() { tooenc "$(__edate)${NULIB__TLEVEL}NOTE: $(__indent "$1" " ")"; }
function __einfo() { tooenc "$(__edate)${NULIB__TLEVEL}INFO: $(__indent "$1" " ")"; }
function __edebug() { tooenc "$(__edate)${NULIB__TLEVEL}DEBUG: $(__indent "$1" " ")"; }
function __eecho() { tooenc "$(__edate)${NULIB__TLEVEL}$(__indent "$1")"; }
function __eecho_() { tooenc_ "$(__edate)${NULIB__TLEVEL}$(__indent "$1")"; }
function __eimportant() { tooenc "$(__edate)$(__eindent0)IMPORTANT! $(__eindent "$1" " ")"; }
function __eattention() { tooenc "$(__edate)$(__eindent0)ATTENTION! $(__eindent "$1" " ")"; }
function __eerror() { tooenc "$(__edate)$(__eindent0)ERROR: $(__eindent "$1" " ")"; }
function __ewarn() { tooenc "$(__edate)$(__eindent0)WARNING: $(__eindent "$1" " ")"; }
function __enote() { tooenc "$(__edate)$(__eindent0)NOTE: $(__eindent "$1" " ")"; }
function __einfo() { tooenc "$(__edate)$(__eindent0)INFO: $(__eindent "$1" " ")"; }
function __edebug() { tooenc "$(__edate)$(__eindent0)DEBUG: $(__eindent "$1" " ")"; }
function __eecho() { tooenc "$(__edate)$(__eindent0)$(__eindent "$1")"; }
function __eecho_() { tooenc_ "$(__edate)$(__eindent0)$(__eindent "$1")"; }
function __estep() { tooenc "$(__edate)${NULIB__TLEVEL}. $(__indent "$1" " ")"; }
function __estepe() { tooenc "$(__edate)${NULIB__TLEVEL}.E $(__indent "$1" " ")"; }
function __estepw() { tooenc "$(__edate)${NULIB__TLEVEL}.W $(__indent "$1" " ")"; }
function __estepn() { tooenc "$(__edate)${NULIB__TLEVEL}.N $(__indent "$1" " ")"; }
function __estepi() { tooenc "$(__edate)${NULIB__TLEVEL}.I $(__indent "$1" " ")"; }
function __estep_() { tooenc_ "$(__edate)${NULIB__TLEVEL}. $(__indent "$1" " ")"; }
function __estepe_() { tooenc_ "$(__edate)${NULIB__TLEVEL}.E $(__indent "$1" " ")"; }
function __estepw_() { tooenc_ "$(__edate)${NULIB__TLEVEL}.W $(__indent "$1" " ")"; }
function __estepn_() { tooenc_ "$(__edate)${NULIB__TLEVEL}.N $(__indent "$1" " ")"; }
function __estepi_() { tooenc_ "$(__edate)${NULIB__TLEVEL}.I $(__indent "$1" " ")"; }
function __estep() { tooenc "$(__edate)$(__eindent0). $(__eindent "$1" " ")"; }
function __estepe() { tooenc "$(__edate)$(__eindent0).E $(__eindent "$1" " ")"; }
function __estepw() { tooenc "$(__edate)$(__eindent0).W $(__eindent "$1" " ")"; }
function __estepn() { tooenc "$(__edate)$(__eindent0).N $(__eindent "$1" " ")"; }
function __estepi() { tooenc "$(__edate)$(__eindent0).I $(__eindent "$1" " ")"; }
function __estep_() { tooenc_ "$(__edate)$(__eindent0). $(__eindent "$1" " ")"; }
function __estepe_() { tooenc_ "$(__edate)$(__eindent0).E $(__eindent "$1" " ")"; }
function __estepw_() { tooenc_ "$(__edate)$(__eindent0).W $(__eindent "$1" " ")"; }
function __estepn_() { tooenc_ "$(__edate)$(__eindent0).N $(__eindent "$1" " ")"; }
function __estepi_() { tooenc_ "$(__edate)$(__eindent0).I $(__eindent "$1" " ")"; }
function __ebegin() { tooenc_ "$(__edate)${NULIB__TLEVEL}. $(__indent "$1" " "): "; }
function __edoto() { echo_ "."; }
function __edotw() { echo_ "w"; }
function __edotx() { echo_ "x"; }
function __edotp() { echo_ "+"; }
function __edotd() { tooenc "($1)"; }
function __eendo() { echo "[ok]"; }
function __eendx() { echo "[error]"; }
function __action() { tooenc "$(__edate)$(__eindent0)ACTION: $(__eindent "$1" " ")"; }
function __asuccess() { tooenc "$(__edate)$(__eindent0)(OK) $(__eindent "$1" " ")"; }
function __afailure() { tooenc "$(__edate)$(__eindent0)(KO) $(__eindent "$1" " ")"; }
function __adone() { tooenc "$(__edate)$(__eindent0)$(__eindent "$1")"; }

View File

@ -106,7 +106,7 @@ function tooenc_() {
}
function uecho_() { tooenc_ "$*"; }
# faut-il dater les messages de etitle, estep, ebegin?
# faut-il dater les messages des fonctions e* et action?
# Faire NULIB_ELOG_DATE=1 en début de script pour activer cette fonctionnalité
# faut-il rajouter aussi le nom du script? (nécessite NULIB_ELOG_DATE)
# Faire NULIB_ELOG_MYNAME=1 en début de script pour activer cette fonctionnalité
@ -197,13 +197,18 @@ function quietc_echo() {
}
# variables utilisées pour l'affichage indenté des messages et des titres
# NULIB__ESTACK est la liste des invocations de 'ebegin' et 'etitle' en cours
# NULIB__TLEVEL est l'indentation à appliquer avant d'afficher le message
export NULIB__ESTACK NULIB__TLEVEL
function __indent() {
# NULIB__ESTACK est la liste des invocations de 'etitle' et 'action' en cours
export NULIB__ESTACK NULIB__INDENT=
function __eindent0() {
# afficher le nombre d'espaces correspondant à l'indentation
local indent="${NULIB__ESTACK//?/ }"
indent="${indent% }$NULIB__INDENT"
[ -n "$indent" ] && echo "$indent"
}
function __eindent() {
# indenter les lignes de $1, sauf la première
local -a lines; local line first=1
local indent="$NULIB__TLEVEL$2"
local indent="$(__eindent0)$2"
setx -a lines=echo "$1"
for line in "${lines[@]}"; do
if [ -n "$first" ]; then
@ -245,21 +250,18 @@ function esection() {
show_info || return
eval "$NULIB__DISABLE_SET_X"
NULIB__ESTACK=
NULIB__TLEVEL=
__esection "$*" 1>&2
eval "$NULIB__ENABLE_SET_X"
}
function etitle() {
# Afficher le titre $1. Le contenu sous des titres imbriqués est affiché
# indenté. le titre n'est pas terminé, et il faut le terminer explicitement
# avec eend, sauf dans certains cas précis:
# - Si $2..$* est spécifié, c'est une commande. Lancer la commande dans le
# contexte du titre. Puis, le titre est automatiquement terminé
# - Sinon, le titre doit toujours être terminé explicitement.
# indenté.
# - si $2..$* est spécifié, c'est une commande qui est lancée dans le contexte
# du titre, ensuite le titre est automatiquement terminé
# - sinon il faut terminer le titre explicitement avec eend
local title="$1"; shift
# etitle
[ -n "$NULIB__ESTACK" ] && NULIB__TLEVEL="${NULIB__TLEVEL} "
NULIB__ESTACK="$NULIB__ESTACK:t"
if show_info; then
eval "$NULIB__DISABLE_SET_X"
@ -270,11 +272,19 @@ function etitle() {
local r=0
if [ $# -gt 0 ]; then
"$@"; r=$?
eend $r
eend
fi
return $r
}
function eend() {
# Terminer un titre
if [ "${NULIB__ESTACK%:t}" != "$NULIB__ESTACK" ]; then
NULIB__ESTACK="${NULIB__ESTACK%:t}"
fi
}
function edesc() {
# Afficher une description sous le titre courant
show_info || return
@ -495,159 +505,70 @@ function estepw_() { show_info || return; eval "$NULIB__DISABLE_SET_X"; __estepw
function estepn_() { show_info || return; eval "$NULIB__DISABLE_SET_X"; __estepn_ "$*" 1>&2; eval "$NULIB__ENABLE_SET_X"; }
function estepi_() { show_info || return; eval "$NULIB__DISABLE_SET_X"; __estepi_ "$*" 1>&2; eval "$NULIB__ENABLE_SET_X"; }
function ebegin() {
# Afficher le message $1, qui décrit le début d'une opération. Cette fonction
# débute une section, qu'il faut terminer avec eend.
# Si $2..$* est spécifié, c'est une commande. Lancer la commande dans le
# contexte de la section. Puis, la section est terminée automatiquement, sauf si
# l'option -s est spécifiée, auquel cas la section reste ouverte.
local __b_eend=default
while [ -n "$1" ]; do
if [ "$1" == "--" ]; then
shift
break
elif [ "$1" == "-s" ]; then
__b_eend=
shift
elif [ "$1" == "--eend" ]; then
__b_eend=1
shift
else
break
fi
done
local __b_msg="$1"; shift
local __b_s=0
# ebegin
NULIB__ESTACK="$NULIB__ESTACK:b"
if show_info; then
__ebegin "$__b_msg" 1>&2
fi
# commande
function action() {
show_info || return
eval "$NULIB__DISABLE_SET_X"
local action="$1"; shift
local r=0
if [ $# -gt 0 ]; then
"$@"
__b_s=$?
[ "$__b_eend" == "default" ] && __b_eend=1
"$@"; r=$?
if [ $r -eq 0 ]; then
[ -n "$action" ] || action="succès"
__asuccess "$action" 1>&2
else
[ -n "$action" ] || action="échec"
__afailure "$action" 1>&2
fi
# eend
[ "$__b_eend" == "default" ] && __b_eend=
[ -n "$__b_eend" ] && eend $__b_s
return $__b_s
else
NULIB__ESTACK="$NULIB__ESTACK:a"
__action "$action:" 1>&2
fi
eval "$NULIB__ENABLE_SET_X"
}
function edot() {
# Afficher une étape d'une opération, matérialisée par un point '.' ou une
# croix 'x' en cas de succès ou d'erreur. Cette fonction est particulièrement
# appropriée dans le contexte d'un ebegin.
local s=$?
function asuccess() {
# terminer l'action en cours avec le message de succès $*
show_info || return
[ -n "$1" ] && s="$1"
shift
if [ "$s" == "0" ]; then
__edoto 1>&2
else
__edotx 1>&2
fi
show_verbose && [ $# -gt 0 ] && __edotd "$*" 1>&2
return $s
[ "${NULIB__ESTACK%:a}" != "$NULIB__ESTACK" ] || return
eval "$NULIB__DISABLE_SET_X"
[ -n "$*" ] || set -- "succès"
NULIB__INDENT=" " __asuccess "$*" 1>&2
NULIB__ESTACK="${NULIB__ESTACK%:a}"
eval "$NULIB__ENABLE_SET_X"
}
function edotw() {
# Afficher un avertissement comme étape d'une opération, matérialisée par une
# lettre 'w' (typiquement de couleur jaune). Cette fonction est particulièrement
# appropriée dans le contexte d'un ebegin.
local s=$?
function afailure() {
# terminer l'action en cours avec le message d'échec $*
show_info || return
[ -n "$1" ] && s="$1"
shift
__edotw 1>&2
show_verbose && [ $# -gt 0 ] && __edotd "$*" 1>&2
return $s
[ "${NULIB__ESTACK%:a}" != "$NULIB__ESTACK" ] || return
eval "$NULIB__DISABLE_SET_X"
[ -n "$*" ] || set -- "échec"
NULIB__INDENT=" " __afailure "$*" 1>&2
NULIB__ESTACK="${NULIB__ESTACK%:a}"
eval "$NULIB__ENABLE_SET_X"
}
function ewait() {
# Afficher les étapes d'une opération qui dure, matérialisées par des '+' toutes
# les secondes tant que le processus $1 tourne.
# A utiliser de cette manière:
# ebegin "msg"
# cmd &
# ewait $!
# eend
[ -n "$1" ] || return 1
if show_info; then
local count=2
little_sleep # certains processus retournent tout de suite
while is_running "$1"; do
sleep 1
if [ $count -gt 0 ]; then
# attendre 2 secondes avant de commencer à afficher des '+'
count=$(($count - 1))
else
__edotp 1>&2
fi
done
# terminer par un '.'
__edoto 1>&2
else
# ne rien afficher, mais attendre quand même la fin de l'opération
wait "$1"
fi
}
function eend() {
# Terminer une section.
# Avec l'option -c, remettre à zéro toutes les informations de section
# Si la section en cours est un ebegin, afficher la fin de l'opération: [ok] ou
# [error] en fonction du code de retour de la dernière commande (ou de $1 si
# cette valeur est donnée)
# Si la section en cours est un etitle, marquer la fin de la section concernée
# par le titre.
local s=$?
if [ "$1" == "-c" ]; then
NULIB__ESTACK=
NULIB__TLEVEL=
elif [ "${NULIB__ESTACK%:b}" != "$NULIB__ESTACK" ]; then
# terminer ebegin
NULIB__ESTACK="${NULIB__ESTACK%:b}"
function aresult() {
# terminer l'action en cours avec un message de succès ou d'échec $2..* en
# fonction du code de retour $1 (0=succès, sinon échec)
show_info || return
[ -n "$1" ] && s="$1"
if [ "$s" == "0" ]; then
__eendo 1>&2
[ "${NULIB__ESTACK%:a}" != "$NULIB__ESTACK" ] || return
eval "$NULIB__DISABLE_SET_X"
local r="${1:-0}"; shift
if [ "$r" == 0 ]; then
[ -n "$*" ] || set -- "succès"
NULIB__INDENT=" " __asuccess "$*" 1>&2
else
__eendx 1>&2
fi
elif [ "${NULIB__ESTACK%:t}" != "$NULIB__ESTACK" ]; then
# terminer etitle -s
NULIB__ESTACK="${NULIB__ESTACK%:t}"
NULIB__TLEVEL="${NULIB__TLEVEL% }"
[ -n "$*" ] || set -- "échec"
NULIB__INDENT=" " __afailure "$*" 1>&2
fi
NULIB__ESTACK="${NULIB__ESTACK%:a}"
eval "$NULIB__ENABLE_SET_X"
}
function __elinedots() {
ebegin "$1"
local line
if show_debug; then
while read line; do
__edoto 1>&2
__edotd "$line" 1>&2
done
else
while read line; do
__edoto 1>&2
done
fi
eend
}
function elinedots() {
# Afficher un message comme avec ebegin "$1", puis afficher un point '.' pour
# chaque ligne lue sur stdin. Cela permet de suivre une opération. En mode
# DEBUG, afficher la ligne affichée plutôt qu'un point.
# Si $2..$* sont spécifiés, lancer la commande et suivre sa sortie. Ainsi,
# 'elinedots msg cmd args' est un raccourci pour 'cmd args | elinedots msg'
local msg="$1"; shift
if [ $# -gt 0 ]; then
"$@" | __elinedots "$msg"
else
__elinedots "$msg"
fi
function adone() {
# terminer l'action en cours avec le message neutre $*
show_info || return
[ "${NULIB__ESTACK%:a}" != "$NULIB__ESTACK" ] || return
eval "$NULIB__DISABLE_SET_X"
[ -n "$*" ] && NULIB__INDENT=" " __adone "$*" 1>&2
NULIB__ESTACK="${NULIB__ESTACK%:a}"
eval "$NULIB__ENABLE_SET_X"
}

View File

@ -3,15 +3,58 @@
source "$(dirname -- "$0")/../src/nulib.sh" || exit 1
#NULIB_NO_DISABLE_SET_X=1
Multiline=
Banner=
args=(
"afficher divers messages avec les fonctions e*"
-d,--date NULIB_ELOG_DATE=1
-m,--myname NULIB_ELOG_MYNAME=1
-n,--no-color '$__set_no_colors 1'
-n,--nc,--no-color '$__set_no_colors 1'
--ml Multiline=1
-b Banner=1
)
parse_args "$@"; set -- "${args[@]}"
#ebanner "banner"
if [ -n "$Multiline" ]; then
############################################################################
[ -n "$Banner" ] && ebanner $'multi-line\nbanner'
esection $'multi-line\nsection'
etitle $'multi-line\ntitle'
etitle $'another\ntitle'
edesc $'multi-line\ndesc'
[ -n "$Banner" ] && ebanner $'multi-line\nbanner'
eimportant $'multi-line\nimportant'
eattention $'multi-line\nattention'
eerror $'multi-line\nerror'
ewarn $'multi-line\nwarn'
enote $'multi-line\nnote'
einfo $'multi-line\ninfo'
eecho $'multi-line\necho'
edebug $'multi-line\ndebug'
action $'multi-line\naction'
asuccess
action $'multi-line\naction'
estep $'multi-line\nstep'
afailure
action $'multi-line\naction'
estep $'multi-line\nstep'
asuccess $'multi-line\nsuccess'
action $'multi-line\naction'
estep $'multi-line\nstep'
adone $'multi-line\nneutral'
eend
eend
else
############################################################################
[ -n "$Banner" ] && ebanner "banner"
eimportant "important"
eattention "attention"
eerror "error"
@ -26,14 +69,6 @@ estepe "stepe"
estepw "stepw"
estepn "stepn"
estepi "stepi"
ebegin "begin"
edot
edotw
eend
echo "\
line1
line2
line3" | elinedots "lines"
esection "section"
eecho "content"
@ -107,36 +142,19 @@ asuccess
asuccess
asuccess
################################################################################
edesc "action avec commande"
action "commande true" true
action "commande false" false
#ebanner $'multi-line\nbanner'
edesc "action avec commande et aresult sans message"
action "commande true"
true; aresult $?
action "commande false"
false; aresult $?
esection $'multi-line\nsection'
etitle $'multi-line\ntitle'
etitle $'another\ntitle'
edesc $'multi-line\ndesc'
#ebanner $'multi-line\nbanner'
eimportant $'multi-line\nimportant'
eattention $'multi-line\nattention'
eerror $'multi-line\nerror'
ewarn $'multi-line\nwarn'
enote $'multi-line\nnote'
einfo $'multi-line\ninfo'
eecho $'multi-line\necho'
edebug $'multi-line\ndebug'
action $'multi-line\naction'
asuccess
action $'multi-line\naction'
estep $'multi-line\nstep'
afailure
action $'multi-line\naction'
estep $'multi-line\nstep'
asuccess $'multi-line\nsuccess'
action $'multi-line\naction'
estep $'multi-line\nstep'
adone $'multi-line\ndone'
eend
eend
edesc "action avec commande et aresult"
action "commande true"
true; aresult $? "résultat de la commande"
action "commande false"
false; aresult $? "résultat de la commande"
fi