Browse Source

fixed ask_yn again

main
deicidus 1 year ago
parent
commit
468ad4017f
  1. 15
      spells/cantrips/ask_yn

15
spells/cantrips/ask_yn

@ -5,17 +5,18 @@
ask_yn() { ask_yn() {
default=${2:-"y"} default=${2:-"y"}
default=$(echo "$default" | tr '[:upper:]' '[:lower:]') default=$(printf "%s" "$default" | tr '[:upper:]' '[:lower:]')
# Set prompt string # Set prompt string
case "$default" in case "$default" in
y) prompt="Y/n" ;; y) prompt="Y/n" ;;
n) prompt="y/N" ;; n) prompt="y/N" ;;
*) echo "Invalid default answer"; exit 1 ;; *) printf "Invalid default answer\n"; exit 1 ;;
esac esac
while true; do while true; do
echo -n "$1 ($prompt): " trap 'stty sane; exit' INT
printf "%s (%s): " "$1" "$prompt"
stty raw -echo stty raw -echo
answer=$(head -c 1) || exit answer=$(head -c 1) || exit
stty -echo stty -echo
@ -28,9 +29,7 @@ ask_yn() {
done done
case "$answer" in case "$answer" in
y|Y) echo 1;; y|Y) printf "1";;
n|N) echo 0;; n|N) printf "0";;
esac esac
} }
ask_yn "$@"
Loading…
Cancel
Save