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

View File

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

View File

@ -106,7 +106,7 @@ function tooenc_() {
} }
function uecho_() { 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é # 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) # 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é # 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 # 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__ESTACK est la liste des invocations de 'etitle' et 'action' en cours
# NULIB__TLEVEL est l'indentation à appliquer avant d'afficher le message export NULIB__ESTACK NULIB__INDENT=
export NULIB__ESTACK NULIB__TLEVEL function __eindent0() {
function __indent() { # 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 # indenter les lignes de $1, sauf la première
local -a lines; local line first=1 local -a lines; local line first=1
local indent="$NULIB__TLEVEL$2" local indent="$(__eindent0)$2"
setx -a lines=echo "$1" setx -a lines=echo "$1"
for line in "${lines[@]}"; do for line in "${lines[@]}"; do
if [ -n "$first" ]; then if [ -n "$first" ]; then
@ -245,21 +250,18 @@ function esection() {
show_info || return show_info || return
eval "$NULIB__DISABLE_SET_X" eval "$NULIB__DISABLE_SET_X"
NULIB__ESTACK= NULIB__ESTACK=
NULIB__TLEVEL=
__esection "$*" 1>&2 __esection "$*" 1>&2
eval "$NULIB__ENABLE_SET_X" eval "$NULIB__ENABLE_SET_X"
} }
function etitle() { function etitle() {
# Afficher le titre $1. Le contenu sous des titres imbriqués est affiché # 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 # indenté.
# avec eend, sauf dans certains cas précis: # - si $2..$* est spécifié, c'est une commande qui est lancée dans le contexte
# - Si $2..$* est spécifié, c'est une commande. Lancer la commande dans le # du titre, ensuite le titre est automatiquement terminé
# contexte du titre. Puis, le titre est automatiquement terminé # - sinon il faut terminer le titre explicitement avec eend
# - Sinon, le titre doit toujours être terminé explicitement.
local title="$1"; shift local title="$1"; shift
# etitle # etitle
[ -n "$NULIB__ESTACK" ] && NULIB__TLEVEL="${NULIB__TLEVEL} "
NULIB__ESTACK="$NULIB__ESTACK:t" NULIB__ESTACK="$NULIB__ESTACK:t"
if show_info; then if show_info; then
eval "$NULIB__DISABLE_SET_X" eval "$NULIB__DISABLE_SET_X"
@ -270,11 +272,19 @@ function etitle() {
local r=0 local r=0
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
"$@"; r=$? "$@"; r=$?
eend $r eend
fi fi
return $r return $r
} }
function eend() {
# Terminer un titre
if [ "${NULIB__ESTACK%:t}" != "$NULIB__ESTACK" ]; then
NULIB__ESTACK="${NULIB__ESTACK%:t}"
fi
}
function edesc() { function edesc() {
# Afficher une description sous le titre courant # Afficher une description sous le titre courant
show_info || return 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 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 estepi_() { show_info || return; eval "$NULIB__DISABLE_SET_X"; __estepi_ "$*" 1>&2; eval "$NULIB__ENABLE_SET_X"; }
function ebegin() { function action() {
# Afficher le message $1, qui décrit le début d'une opération. Cette fonction show_info || return
# débute une section, qu'il faut terminer avec eend. eval "$NULIB__DISABLE_SET_X"
# Si $2..$* est spécifié, c'est une commande. Lancer la commande dans le local action="$1"; shift
# contexte de la section. Puis, la section est terminée automatiquement, sauf si local r=0
# 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
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
"$@" "$@"; r=$?
__b_s=$? if [ $r -eq 0 ]; then
[ "$__b_eend" == "default" ] && __b_eend=1 [ -n "$action" ] || action="succès"
__asuccess "$action" 1>&2
else
[ -n "$action" ] || action="échec"
__afailure "$action" 1>&2
fi fi
# eend else
[ "$__b_eend" == "default" ] && __b_eend= NULIB__ESTACK="$NULIB__ESTACK:a"
[ -n "$__b_eend" ] && eend $__b_s __action "$action:" 1>&2
return $__b_s fi
eval "$NULIB__ENABLE_SET_X"
} }
function edot() { function asuccess() {
# Afficher une étape d'une opération, matérialisée par un point '.' ou une # terminer l'action en cours avec le message de succès $*
# 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=$?
show_info || return show_info || return
[ -n "$1" ] && s="$1" [ "${NULIB__ESTACK%:a}" != "$NULIB__ESTACK" ] || return
shift eval "$NULIB__DISABLE_SET_X"
if [ "$s" == "0" ]; then [ -n "$*" ] || set -- "succès"
__edoto 1>&2 NULIB__INDENT=" " __asuccess "$*" 1>&2
else NULIB__ESTACK="${NULIB__ESTACK%:a}"
__edotx 1>&2 eval "$NULIB__ENABLE_SET_X"
fi
show_verbose && [ $# -gt 0 ] && __edotd "$*" 1>&2
return $s
} }
function afailure() {
function edotw() { # terminer l'action en cours avec le message d'échec $*
# 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=$?
show_info || return show_info || return
[ -n "$1" ] && s="$1" [ "${NULIB__ESTACK%:a}" != "$NULIB__ESTACK" ] || return
shift eval "$NULIB__DISABLE_SET_X"
__edotw 1>&2 [ -n "$*" ] || set -- "échec"
show_verbose && [ $# -gt 0 ] && __edotd "$*" 1>&2 NULIB__INDENT=" " __afailure "$*" 1>&2
return $s NULIB__ESTACK="${NULIB__ESTACK%:a}"
eval "$NULIB__ENABLE_SET_X"
} }
function aresult() {
function ewait() { # terminer l'action en cours avec un message de succès ou d'échec $2..* en
# Afficher les étapes d'une opération qui dure, matérialisées par des '+' toutes # fonction du code de retour $1 (0=succès, sinon échec)
# 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}"
show_info || return show_info || return
[ -n "$1" ] && s="$1" [ "${NULIB__ESTACK%:a}" != "$NULIB__ESTACK" ] || return
if [ "$s" == "0" ]; then eval "$NULIB__DISABLE_SET_X"
__eendo 1>&2 local r="${1:-0}"; shift
if [ "$r" == 0 ]; then
[ -n "$*" ] || set -- "succès"
NULIB__INDENT=" " __asuccess "$*" 1>&2
else else
__eendx 1>&2 [ -n "$*" ] || set -- "échec"
fi NULIB__INDENT=" " __afailure "$*" 1>&2
elif [ "${NULIB__ESTACK%:t}" != "$NULIB__ESTACK" ]; then
# terminer etitle -s
NULIB__ESTACK="${NULIB__ESTACK%:t}"
NULIB__TLEVEL="${NULIB__TLEVEL% }"
fi fi
NULIB__ESTACK="${NULIB__ESTACK%:a}"
eval "$NULIB__ENABLE_SET_X"
} }
function adone() {
function __elinedots() { # terminer l'action en cours avec le message neutre $*
ebegin "$1" show_info || return
local line [ "${NULIB__ESTACK%:a}" != "$NULIB__ESTACK" ] || return
if show_debug; then eval "$NULIB__DISABLE_SET_X"
while read line; do [ -n "$*" ] && NULIB__INDENT=" " __adone "$*" 1>&2
__edoto 1>&2 NULIB__ESTACK="${NULIB__ESTACK%:a}"
__edotd "$line" 1>&2 eval "$NULIB__ENABLE_SET_X"
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
} }

View File

@ -3,15 +3,58 @@
source "$(dirname -- "$0")/../src/nulib.sh" || exit 1 source "$(dirname -- "$0")/../src/nulib.sh" || exit 1
#NULIB_NO_DISABLE_SET_X=1 #NULIB_NO_DISABLE_SET_X=1
Multiline=
Banner=
args=( args=(
"afficher divers messages avec les fonctions e*" "afficher divers messages avec les fonctions e*"
-d,--date NULIB_ELOG_DATE=1 -d,--date NULIB_ELOG_DATE=1
-m,--myname NULIB_ELOG_MYNAME=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[@]}" 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" eimportant "important"
eattention "attention" eattention "attention"
eerror "error" eerror "error"
@ -26,14 +69,6 @@ estepe "stepe"
estepw "stepw" estepw "stepw"
estepn "stepn" estepn "stepn"
estepi "stepi" estepi "stepi"
ebegin "begin"
edot
edotw
eend
echo "\
line1
line2
line3" | elinedots "lines"
esection "section" esection "section"
eecho "content" eecho "content"
@ -107,36 +142,19 @@ asuccess
asuccess 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' edesc "action avec commande et aresult"
etitle $'multi-line\ntitle' action "commande true"
etitle $'another\ntitle' true; aresult $? "résultat de la commande"
edesc $'multi-line\ndesc' action "commande false"
false; aresult $? "résultat de la commande"
#ebanner $'multi-line\nbanner' fi
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