From 50a2f517370bdc2fdd81917e4ebe28de50670d2e Mon Sep 17 00:00:00 2001 From: deicidus Date: Sat, 6 May 2023 22:30:15 -0700 Subject: [PATCH] more POSIX --- spells/cantrips/fathom-cursor | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/spells/cantrips/fathom-cursor b/spells/cantrips/fathom-cursor index b83048f..42ad24b 100755 --- a/spells/cantrips/fathom-cursor +++ b/spells/cantrips/fathom-cursor @@ -17,7 +17,21 @@ fathom_cursor() { done # Get the position of the cursor - position=$(stty -echo; printf "\033[6n"; (trap 'exit 142' ALRM; sh -c 'sleep 0.1; kill -ALRM $$' &) IFS=';' read -r ROW COL; stty echo; printf "%s;%s" "${ROW#*[}" "${COL}") + + # Save the current terminal state + old_state=$(stty -g) + + # Disable terminal echo and canonical mode + stty -echo -icanon + + # Request the cursor position + printf "\033[6n" + IFS='[;' read -r _ ROW COL + + # Restore the terminal state + stty "$old_state" + + position="$COL;$ROW" if [ $x = true ] && [ $y = true ]; then if [ $verbose = true ]; then