diff --git a/bash/src/base.output.sh b/bash/src/base.output.sh index 0f8b1fa..5805a24 100644 --- a/bash/src/base.output.sh +++ b/bash/src/base.output.sh @@ -106,20 +106,28 @@ function tooenc_() { function uecho_() { tooenc_ "$*"; } # faut-il dater les messages de etitle, estep, ebegin? -# Faire NULIB_EDATE=1 en début de script pour activer cette fonctionnalité -export NULIB_EDATE -function __edate() { [ -n "$NULIB_EDATE" ] && date +"[%d/%m/%Y-%H:%M:%S] "; } +# 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é +export NULIB_ELOG_DATE NULIB_ELOG_MYNAME +function __edate() { + [ -n "$NULIB_ELOG_DATE" ] || return + local prefix="$(date +"[%d/%m/%Y-%H:%M:%S] ")" + [ -n "$NULIB_ELOG_MYNAME" ] && prefix="$prefix$MYNAME " + echo "$prefix" +} export NULIB_ELOG_OVERWRITE function __set_no_colors() { :; } function elogto() { -# Activer NULIB_EDATE et rediriger STDOUT et STDERR vers le fichier $1 +# Activer NULIB_ELOG_DATE et rediriger STDOUT et STDERR vers le fichier $1 # Si deux fichiers sont spécifiés, rediriger STDOUT vers $1 et STDERR vers $2 # Si aucun fichier n'est spécifié, ne pas faire de redirection # Si la redirection est activée, forcer l'utilisation de l'encoding UTF8 # Si NULIB_ELOG_OVERWRITE=1, alors le fichier en sortie est écrasé. Sinon, les # lignes en sortie lui sont ajoutées - NULIB_EDATE=1 + NULIB_ELOG_DATE=1 + NULIB_ELOG_MYNAME=1 if [ -n "$1" -a -n "$2" ]; then LANG=fr_FR.UTF8 NULIB_OUTPUT_ENCODING="$NULIB__UTF8" @@ -160,24 +168,24 @@ function __ewarn() { tooenc "$(__edate)${NULIB__TLEVEL}WARNING $(__indent "$1")" function __enote() { tooenc "$(__edate)${NULIB__TLEVEL}NOTE $(__indent "$1")"; } function __ebanner() { local maxi="${COLUMNS:-80}" + local prefix="$(__edate)${NULIB__TLEVEL}" lsep line local -a lines - local psfix line - psfix="$(__edate)${NULIB__TLEVEL}" - while [ ${#psfix} -lt $maxi ]; do psfix="$psfix="; done + lsep="$prefix" + while [ ${#lsep} -lt $maxi ]; do lsep="$lsep="; done - tooenc "$psfix" + tooenc "$lsep" maxi=$(($maxi - 1)) array_xsplitl lines "$1" for line in "" "${lines[@]}" ""; do - line="$(__edate)${NULIB__TLEVEL}= $line" + line="$prefix= $line" if [ ${#line} -le $maxi ]; then while [ ${#line} -lt $maxi ]; do line="$line "; done line="$line=" fi tooenc "$line" done - tooenc "$psfix" + tooenc "$lsep" } function __eimportant() { tooenc "$(__edate)${NULIB__TLEVEL}IMPORTANT $(__indent "$1")"; } function __eattention() { tooenc "$(__edate)${NULIB__TLEVEL}ATTENTION $(__indent "$1")"; } @@ -195,6 +203,19 @@ 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 __esection() { + local maxi="${COLUMNS:-80}" + local prefix="$(__edate)${NULIB__TLEVEL}" lsep + + lsep="$prefix" + while [ ${#lsep} -lt $maxi ]; do lsep="$lsep="; done + + tooenc "$lsep" + if [ -n "$*" ]; then + tooenc "$prefix$*" + tooenc "$lsep" + fi +} function __etitle() { tooenc "$(__edate)${NULIB__TLEVEL}=== $(__indent "$1")"; } function __ebegin() { tooenc_ "$(__edate)${NULIB__TLEVEL}. $(__indent "$1"): "; } function __edoto() { echo_ "."; } @@ -385,6 +406,10 @@ function trace_error() { return $r } +function esection() { + show_info || return; eflush; __esection "$*" 1>&2 +} + function etitle() { # Afficher le titre $1, qui est le début éventuel d'une section. Les section # imbriquées sont affichées indentées. La section n'est pas terminée, et il faut diff --git a/bash/src/base.sh b/bash/src/base.sh index 36baa3f..b48b079 100644 --- a/bash/src/base.sh +++ b/bash/src/base.sh @@ -9,6 +9,8 @@ fi ##@include base.init.sh ##@include base.core.sh ##@include base.string.sh +##@include base.num.sh +##@include base.bool.sh ##@include base.array.sh ##@include base.output.sh ##@include base.input.sh @@ -16,4 +18,4 @@ fi ##@include base.path.sh ##@include base.args.sh module: base "Chargement de tous les modules base.*" -require: base.init base.core base.string base.array base.output base.input base.split base.path base.args +require: base.init base.core base.string base.num base.bool base.array base.output base.input base.split base.path base.args diff --git a/bash/src/pretty.sh b/bash/src/pretty.sh index b104bb0..ab172be 100644 --- a/bash/src/pretty.sh +++ b/bash/src/pretty.sh @@ -70,24 +70,24 @@ function __ewarn() { local p; [ -z "$NO_COLORS" ] && p="W" || p="WARNING"; function __enote() { local p; [ -z "$NO_COLORS" ] && p="N" || p="NOTE"; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_VERTE}${p}${COULEUR_NORMALE} $(__indent "$1")"; } function __ebanner() { local maxi="${COLUMNS:-80}" + local prefix="$(__edate)${NULIB__TLEVEL}" lsep line local -a lines - local psfix line - psfix="$(__edate)${NULIB__TLEVEL}" - while [ ${#psfix} -lt $maxi ]; do psfix="$psfix="; done + lsep="$prefix" + while [ ${#lsep} -lt $maxi ]; do lsep="$lsep="; done - tooenc "$COULEUR_ROUGE$psfix" + tooenc "$COULEUR_ROUGE$lsep" maxi=$(($maxi - 1)) array_xsplitl lines "$1" for line in "" "${lines[@]}" ""; do - line="$(__edate)${NULIB__TLEVEL}= $line" + line="$prefix= $line" if [ ${#line} -le $maxi ]; then while [ ${#line} -lt $maxi ]; do line="$line "; done line="$line=" fi tooenc "$line" done - tooenc "$psfix$COULEUR_NORMALE" + tooenc "$lsep$COULEUR_NORMALE" } function __eimportant() { local p; [ -z "$NO_COLORS" ] && p="!" || p="IMPORTANT"; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_ROUGE}${p}${COULEUR_NORMALE} $(__indent "$1")"; } function __eattention() { local p; [ -z "$NO_COLORS" ] && p="*" || p="ATTENTION"; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_JAUNE}${p}${COULEUR_NORMALE} $(__indent "$1")"; } @@ -103,6 +103,21 @@ function __estepe_() { local p; [ -z "$NO_COLORS" ] && p="." || p=".E"; tooen function __estepw_() { local p; [ -z "$NO_COLORS" ] && p="." || p=".W"; tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_JAUNE}${p}${COULEUR_NORMALE} $(__indent "$1")"; } function __estepn_() { local p; [ -z "$NO_COLORS" ] && p="." || p=".N"; tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_VERTE}${p}${COULEUR_NORMALE} $(__indent "$1")"; } function __estepi_() { local p; [ -z "$NO_COLORS" ] && p="." || p=".I"; tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_BLEUE}${p}${COULEUR_NORMALE} $(__indent "$1")"; } +function __esection() { + local maxi="${COLUMNS:-80}" + local prefix="$(__edate)${NULIB__TLEVEL}" lsep + + lsep="$prefix" + while [ ${#lsep} -lt $maxi ]; do lsep="$lsep="; done + + if [ -n "$*" ]; then + tooenc "$COULEUR_BLEUE$lsep" + tooenc "$prefix$*" + tooenc "$lsep$COULEUR_NORMALE" + else + tooenc "$COULEUR_BLEUE$lsep$COULEUR_NORMALE" + fi +} function __etitle() { local p; [ -z "$NO_COLORS" ] && p="T" || p="==="; tooenc "$(__edate)${NULIB__TLEVEL}${COULEUR_BLEUE}${p} $(get_color _)$(__indent "$1")${COULEUR_NORMALE}"; } function __ebegin() { local p; [ -z "$NO_COLORS" ] && p="." || p="."; tooenc_ "$(__edate)${NULIB__TLEVEL}${COULEUR_BLANCHE}${p}${COULEUR_NORMALE} $(__indent "$1"): "; } function __edoto() { echo_ "."; } diff --git a/bash/tests/test-output.sh b/bash/tests/test-output.sh index fdba57c..5917add 100755 --- a/bash/tests/test-output.sh +++ b/bash/tests/test-output.sh @@ -3,6 +3,14 @@ source "$(dirname -- "$0")/../src/nulib.sh" || exit 1 #NULIB_NO_DISABLE_SET_X=1 +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' +) +parse_args "$@"; set -- "${args[@]}" + eerror "erreur" ewarn "warning" enote "note" @@ -12,8 +20,9 @@ eattention "attention" einfo "info" eecho "vanilla" edebug "debug" +esection -etitle "section" +etitle "title" estep "step" estepe "stepe" @@ -31,3 +40,5 @@ line3" | elinedots "lines" eend +esection "section" +eecho "content"