summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Fink2026-05-14 12:55:07 +0200
committerDennis Fink2026-05-14 12:55:07 +0200
commit99e4756dc12650967cf18f3b93f38629cd09b232 (patch)
tree0e48595ba7ac2c6b6cfdbbbb1b6de391f47685a5
parentdc3d2cb05800d866972b7ba32022428e8474beaa (diff)
downloadtranscode.sh-99e4756dc12650967cf18f3b93f38629cd09b232.tar.gz
transcode.sh-99e4756dc12650967cf18f3b93f38629cd09b232.zip
refactor(output): centralize formatted terminal messages
Add a shared emit() helper for styled terminal output and route error(), msg(), warn(), verbose(), and debug() through it. This removes duplicated printf formatting across the output helpers while keeping the existing prefixes, colors, quiet/verbose/debug gating, and stderr handling for errors. emit() also joins additional message arguments into a single trailing string, matching the output pattern used by the individual helpers. The output helpers now differ only in their prefix, color, and visibility condition, making future formatting changes easier and less error-prone.
Diffstat (limited to '')
-rwxr-xr-xtranscode.sh44
1 files changed, 30 insertions, 14 deletions
diff --git a/transcode.sh b/transcode.sh
index 1fd1fe0..9fca292 100755
--- a/transcode.sh
+++ b/transcode.sh
@@ -196,41 +196,57 @@ readonly EXIT_OK EXIT_RUNTIME_FAILURE EXIT_USAGE_ERROR EXIT_CONFIG_ERROR EXIT_MI
# functions and runtime behaviour such as displaying usage instructions.
###############################################################################
-error() {
+emit() {
+ local prefix="$1"
+ local color="$2"
+ shift 2
+
+ if [[ $# -eq 0 ]]; then
+ printf "%b%s%b\n" "${BOLD}${color}" "$prefix" "$ALL_OFF"
+ return
+ fi
+
local mesg="$1"
shift
- printf "${BOLD}${RED}==> ERROR:${ALL_OFF} ${BOLD}%s${ALL_OFF} %s\n" "$mesg" "$@" >&2
+
+ local rest=""
+ if [[ $# -gt 0 ]]; then
+ printf -v rest ' %s' "$@"
+ rest="${rest# }"
+ fi
+
+ printf "%b%s%b %b%s%b" "${BOLD}${color}" "$prefix" "$ALL_OFF" "$BOLD" "$mesg" "$ALL_OFF"
+ if [[ -n "$rest" ]]; then
+ printf " %s" "$rest"
+ fi
+ printf "\n"
+}
+
+error() {
+ emit "==> ERROR:" "$RED" "$@" >&2
}
msg() {
if [[ $QUIET -eq 0 ]]; then
- local mesg="$1"
- shift
- printf "${BOLD}${GREEN}==>${ALL_OFF} ${BOLD}%s${ALL_OFF} %s\n" "$mesg" "$@"
+ emit "==>" "$GREEN" "$@"
fi
}
warn() {
if [[ $QUIET -eq 0 ]]; then
- local mesg="$1"
- shift
- printf "${BOLD}${YELLOW}==>${ALL_OFF} ${BOLD}%s${ALL_OFF} %s\n" "$mesg" "$@"
+ emit "==>" "$YELLOW" "$@"
fi
}
verbose() {
if [[ $VERBOSE -eq 1 && $QUIET -eq 0 ]]; then
- local mesg="$1"
- shift
- printf "${BOLD}${BLUE}==>${ALL_OFF} ${BOLD}%s${ALL_OFF} %s\n" "$mesg" "$@"
+ emit "==>" "$BLUE" "$@"
fi
}
debug() {
if [[ $DEBUG -eq 1 ]]; then
- local mesg="$1"
- shift
- printf "${BOLD}${MAGENTA}==> DEBUG:${ALL_OFF} ${BOLD}%s${ALL_OFF} %s\n" "$mesg" "$@"
+ emit "==> DEBUG:" "$MAGENTA" "$@"
fi
}