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