From 97e3332af9f702dbb01b281e692ec908b48e6d90 Mon Sep 17 00:00:00 2001 From: deicidus Date: Thu, 8 Jun 2023 15:00:17 -0700 Subject: [PATCH] ask_yn works perfectly on Arch --- spells/cantrips/ask_yn | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spells/cantrips/ask_yn b/spells/cantrips/ask_yn index cd0b1ee..7aad0a6 100755 --- a/spells/cantrips/ask_yn +++ b/spells/cantrips/ask_yn @@ -14,20 +14,20 @@ fi old_stty_cfg=$(stty -g) # Use stty to make read command work for single character input -stty raw -echo +stty raw -echo printf "%s" "$prompt" >&2 while true do - answer=$(head -c 1) - if [ "$answer" = $'\n' ] || [ "$answer" = $'\r' ]; then - answer="" - break - elif printf "%s" "$answer" | grep -iq "^y\|^n"; then + answer=$(dd bs=1 count=1 2>/dev/null) + if printf "%s" "$answer" | grep -iq "^y\|^n"; then break - elif [ "$answer" = $'\003' ]; then + elif [ "$(printf "%d" "'$answer'")" -eq 3 ]; then stty "$old_stty_cfg" printf '\n' exit 2 + elif [ "$(printf "%d" "'$answer'")" -eq 13 ]; then + answer="" + break fi done stty "$old_stty_cfg" >&2 # Restore original stty configuration