sequencer - add more options to info,warning,... output

This commit is contained in:
2022-06-11 09:43:53 +02:00
parent 63169f3153
commit ad93a5eb9c

View File

@@ -319,7 +319,9 @@ USAGE_API
Output [STRING] (can be multiline) to stdout according to log level.
[OPTIONS]
-a : Append [STRING] skipping leading " [ ] " prefix
-d : No leading " [ ] " prefix
-e : Output to stderr
-n : No newline
USAGE_API
echo -e "${col_green} echoinfo [...]${col_off}"
@@ -382,14 +384,18 @@ USAGE_API
# Construct log messages
#
# [OPTIONS]
# -a : append text (no info and timestamp)
# -a : append text (placeholder for info and timestamp)
# Uses color from last sqr::log call without -a
# -d : no info and timestamp
# -e : Output to stderr
# -n : no newline
# -- : End of options
#
sqr::log () {
sqr::debugPause
local appendText=
local direct=0 # no prefix and timestamp
local newline='\n'
local col_end="${col_off}"
local outp='/dev/stdout'
@@ -397,18 +403,28 @@ USAGE_API
shift
local log_color="${1:-}"
shift
for _ in "${@}" ; do
case "${1:-}" in
--)
shift && break ;;
-a)
appendText=1
shift ;;
-e)
outp='/dev/stderr'
shift ;;
# Only output newline on empty args
if ! (( $# )) ; then
direct=1
newline='\n'
fi
while getopts "aden" arg; do
case "${arg}" in
a)
appendText=1 ;;
d)
direct=1 ;;
e)
outp='/dev/stderr' ;;
n)
newline='' ;;
*)
;;
esac
done
shift "$((OPTIND-1))"; OPTIND=1
[[ -z "${log_color}" ]] && col_end=""
@@ -417,6 +433,7 @@ USAGE_API
while IFS=$'\n' read -r log_line ; do
printf '%b' "${log_color}" >${outp}
if ! (( direct )) ; then
if [[ -n "${LOG_TIME}" ]] ; then
if (( appendText )) ; then
printf '%24s' "" >${outp}
@@ -432,8 +449,12 @@ USAGE_API
# +3 : "[] "
printf "%$((${#log_level} + 4))s%s" "" "${log_line}" >${outp}
fi
else
# direct output
printf '%s' "${log_line}"
fi
printf '%b\n' "${col_end}" >${outp}
printf '%b'"${newline}" "${col_end}" >${outp}
done <<< "${@:-}"
sqr::debugContinue
}
@@ -504,7 +525,7 @@ USAGE_API
esac
}
# Echo additional line to info correctly indented
# Echo correctly indented additional line to info
readonly _sqr_indentHelp=' : '
readonly _sqr_indentExe=' '
readonly _sqr_indentAppendHelp=' '