Browse Source

ask_yn works perfectly on Arch

main
deicidus 1 year ago
parent
commit
97e3332af9
  1. 14
      spells/cantrips/ask_yn

14
spells/cantrips/ask_yn

@ -14,20 +14,20 @@ fi
old_stty_cfg=$(stty -g) old_stty_cfg=$(stty -g)
# Use stty to make read command work for single character input # Use stty to make read command work for single character input
stty raw -echo stty raw -echo
printf "%s" "$prompt" >&2 printf "%s" "$prompt" >&2
while true while true
do do
answer=$(head -c 1) answer=$(dd bs=1 count=1 2>/dev/null)
if [ "$answer" = $'\n' ] || [ "$answer" = $'\r' ]; then if printf "%s" "$answer" | grep -iq "^y\|^n"; then
answer=""
break
elif printf "%s" "$answer" | grep -iq "^y\|^n"; then
break break
elif [ "$answer" = $'\003' ]; then elif [ "$(printf "%d" "'$answer'")" -eq 3 ]; then
stty "$old_stty_cfg" stty "$old_stty_cfg"
printf '\n' printf '\n'
exit 2 exit 2
elif [ "$(printf "%d" "'$answer'")" -eq 13 ]; then
answer=""
break
fi fi
done done
stty "$old_stty_cfg" >&2 # Restore original stty configuration stty "$old_stty_cfg" >&2 # Restore original stty configuration

Loading…
Cancel
Save