From 1d3eb7723500603c0dbb11663926a0503a35efe8 Mon Sep 17 00:00:00 2001 From: yage Date: Wed, 21 Feb 2024 09:28:34 -0700 Subject: [PATCH] v4.0.12 ===================================================================== --- Bug Fixes ---------------------------- - ensure proper return status from zsh/lib/utils/io print functions - ensure user prompt is displayed when required if log-level is 0 --- zsh/lib/utils/io.zsh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/zsh/lib/utils/io.zsh b/zsh/lib/utils/io.zsh index 55c481d..df3950b 100644 --- a/zsh/lib/utils/io.zsh +++ b/zsh/lib/utils/io.zsh @@ -15,26 +15,31 @@ ERROR() { # command encountered an error SUCCESS() { # command completed successfully [[ $SCWRYPTS_LOG_LEVEL -ge 1 ]] \ && PREFIX="SUCCESS ✔" COLOR=$__GREEN PRINT "$@" + return 0 } REMINDER() { # include sysadmin reminder or other important notice to users [[ $SCWRYPTS_LOG_LEVEL -ge 1 ]] \ && PREFIX="REMINDER " COLOR=$__BRIGHT_MAGENTA PRINT "$@" + return 0 } STATUS() { # general status updates (prefer this to generic 'echo') [[ $SCWRYPTS_LOG_LEVEL -ge 2 ]] \ && PREFIX="STATUS " COLOR=$__BLUE PRINT "$@" + return 0 } WARNING() { # warning-level messages; not errors [[ $SCWRYPTS_LOG_LEVEL -ge 3 ]] \ && PREFIX="WARNING " COLOR=$__YELLOW PRINT "$@" + return 0 } DEBUG() { # helpful during development or (sparingly) to help others' development [[ $SCWRYPTS_LOG_LEVEL -ge 4 ]] \ && PREFIX="DEBUG ℹ" COLOR=$__WHITE PRINT "$@" + return 0 } PROMPT() { # you probably want to use yN or INPUT from below @@ -42,6 +47,7 @@ PROMPT() { # you probably want to use yN or INPUT from below && PREFIX="PROMPT " COLOR=$__CYAN PRINT "$@" \ && PREFIX="USER ⌨" COLOR=$__BRIGHT_CYAN PRINT '' --no-line-end \ ; + return 0 } FAIL() { SCWRYPTS_LOG_LEVEL=1 ERROR "${@:2}"; exit $1; } @@ -211,15 +217,21 @@ READ_YN() { # yes/no read is suprisingly tricky local yn PROMPT "${USERPROMPT[@]}" + local PERFORM_FAKE_PROMPT=false case $SKIP_USER_INPUT in true ) yn=y ;; false ) - [[ $FORCE_USER_INPUT =~ true ]] && [[ $SCWRYPTS_LOG_LEVEL -lt 1 ]] \ + [[ $SCWRYPTS_LOG_LEVEL -lt 1 ]] && { + [[ $FORCE_USER_INPUT =~ false ]] && [ ! -t 0 ] \ + || PERFORM_FAKE_PROMPT=true + } + + [[ $PERFORM_FAKE_PROMPT =~ true ]] \ && echo -n "${USERPROMPT[@]} : " >&2 READ ${READ_ARGS[@]} -s -k yn - [[ $FORCE_USER_INPUT =~ true ]] && [[ $SCWRYPTS_LOG_LEVEL -lt 1 ]] \ + [[ $PERFORM_FAKE_PROMPT =~ true ]] \ && echo $yn >&2 ;; esac