ive written the following script to print out the current line and row every time it changes aka every time i press up,down,left or right but the output is always the same:
row:43:col:141
i believe this means top left of the screen where 0 0 would be bottom right, but im not too sure.
heres my script:
#!/bin/bash
echo "press a key"
tput clear
row=$(tput lines)
col=$(tput cols)
while true; do
echo "row:$row:col:$col"
K1=,K2=,K3=
read -s -N1
K1="$REPLY"
read -s -N1 -t 0.001
K2="$REPLY"
read -s -N1 -t 0.001
K3="$REPLY"
key="$K1$K2$K3"
case "$key" in
$'\033[A') tput cuu 1;;
$'\033[B') tput cud 1;;
$'\033[C') tput cuf 1;;
$'\033[D') tput cup $row $(($col-1));;
*) echo "pressed a key!";;
esac
row=$(tput lines)
col=$(tput cols)
done
exit 0
apparently theres no way to move the cursor left using tput, so I used:
tput cup $row $(($col-1))
but this doesn't work either, any ideas how to fix?
Asked by Mathew
(243 rep)
Oct 19, 2023, 03:47 PM
Last activity: Oct 21, 2023, 05:56 AM
Last activity: Oct 21, 2023, 05:56 AM