|
|
@ -16,12 +16,23 @@ fathom_cursor() { |
|
|
|
done |
|
|
|
done |
|
|
|
|
|
|
|
|
|
|
|
# Get the position of the cursor |
|
|
|
# Get the position of the cursor |
|
|
|
stty -echo |
|
|
|
oldstty=$(stty -g) |
|
|
|
printf "\033[6n" |
|
|
|
stty raw -echo min 0 |
|
|
|
oldIFS="$IFS"; IFS=';' read -r ROW COL |
|
|
|
printf "\033[6n" > /dev/tty |
|
|
|
stty echo |
|
|
|
|
|
|
|
position=$(printf "%s;%s" "${ROW#*[}" "${COL%%R*}") |
|
|
|
result="" |
|
|
|
IFS="$oldIFS" |
|
|
|
char="" |
|
|
|
|
|
|
|
while IFS= read -r -n 1 char; do |
|
|
|
|
|
|
|
result="$result$char" |
|
|
|
|
|
|
|
if [ "$char" = "R" ]; then |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
done < /dev/tty |
|
|
|
|
|
|
|
stty "$oldstty" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ROW="${result#*[}" |
|
|
|
|
|
|
|
COL="${result%;R}" |
|
|
|
|
|
|
|
position=$(printf "%s;%s" "$ROW" "$COL") |
|
|
|
|
|
|
|
|
|
|
|
if $x && $y; then |
|
|
|
if $x && $y; then |
|
|
|
if $verbose; then |
|
|
|
if $verbose; then |
|
|
@ -45,14 +56,4 @@ fathom_cursor() { |
|
|
|
fi |
|
|
|
fi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test_fathom_cursor() { |
|
|
|
|
|
|
|
assert_equal "$(./fathom-cursor -x)" "$(./fathom-cursor -y)" "fathom_cursor -x and -y outputs differ" |
|
|
|
|
|
|
|
assert_equal "$(./fathom-cursor -x -v)" "X: $(./fathom-cursor -x)" "fathom_cursor -x and -x -v outputs differ" |
|
|
|
|
|
|
|
assert_equal "$(./fathom-cursor -y -v)" "Y: $(./fathom-cursor -y)" "fathom_cursor -y and -y -v outputs differ" |
|
|
|
|
|
|
|
assert_equal "$(./fathom-cursor -x -y -v)" "X: $(./fathom-cursor -x)\nY: $(./fathom-cursor -y)" "fathom_cursor -x -y and -x -y -v outputs differ" |
|
|
|
|
|
|
|
assert_equal "$(./fathom-cursor -v -x -y)" "Position: $(./fathom-cursor -x -y)" "fathom_cursor -v -x -y and -x -y outputs differ" |
|
|
|
|
|
|
|
assert_equal "$(./fathom-cursor -v)" "$(./fathom-cursor -x -y -v)" "fathom_cursor -v and -x -y -v outputs differ" |
|
|
|
|
|
|
|
assert_equal "$(./fathom-cursor)" "$(./fathom-cursor -x -y)" "fathom_cursor and -x -y outputs differ" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fathom_cursor "$@" |
|
|
|
fathom_cursor "$@" |