Browse Source

reverted with fix

main
deicidus 2 years ago
parent
commit
e44be71ab0
  1. 17
      spells/cantrips/ask_yn

17
spells/cantrips/ask_yn

@ -1,5 +1,8 @@
#!/bin/sh
# Define ask_yn, which asks a yes or no question and defaults to the specified choice.
# Outputs 1 for yes and 0 for no
ask_yn() {
default=${2:-"y"}
default=$(printf "%s" "$default" | tr '[:upper:]' '[:lower:]')
@ -12,14 +15,14 @@ ask_yn() {
esac
while true; do
trap 'exit' INT
trap 'stty sane; exit' INT
printf "%s (%s): " "$1" "$prompt"
read -r answer || exit
if [ -z "$answer" ]; then
answer="$default"
break
fi
stty raw -echo
answer=$(head -c 1) || exit
stty -echo
printf "\n"
case "$answer" in
"" ) answer="$default"; break;;
y|Y) answer="y"; break;;
n|N) answer="n"; break;;
esac
@ -30,3 +33,5 @@ ask_yn() {
n|N) printf "0";;
esac
}
ask_yn "$@"
Loading…
Cancel
Save