Skip to content

Commit

Permalink
v4.0.12
Browse files Browse the repository at this point in the history
=====================================================================

--- 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
  • Loading branch information
wrynegade committed Feb 21, 2024
1 parent 406ee85 commit 1d3eb77
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions zsh/lib/utils/io.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,39 @@ 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
[[ $SCWRYPTS_LOG_LEVEL -ge 1 ]] \
&& 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; }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1d3eb77

Please sign in to comment.