blob: 3134454bb3887fc40afbf8678269eeda09a717cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#!/bin/sh
function cleanup {
stty -echo
printf "\e[?1006;1000l"
}
trap cleanup EXIT
stty -echo
# Enable SGR protocol and button press and release events
printf "\e[?1006;1000h"
while read -n 1 line
do
printf -v ch "%d" \'$line
if [ "27" != "$ch" ]; then
continue
fi
read -n 1 line
if [ "[" != "$line" ]; then
continue
fi
read -n 1 line
if [ "<" != "$line" ]; then
continue
fi
# Read button state
modifier=
while read -n 1 line
do
if [ ";" = "$line" ]; then
# End
break
fi
printf -v modifier "$modifier$line"
done
# Read column
col=
while read -n 1 line
do
if [ ";" = "$line" ]; then
# End
break
fi
printf -v col "$col$line"
done
# Read row
row=
while read -n 1 line
do
if [ "M" = "$line" ] || [ "m" = "$line" ]; then
# End
btn=$line
break
fi
printf -v row "$row$line"
done
if [ "M" = "$btn" ]; then
echo "You pressed at $col x $row (mods: $modifier)"
else
echo "You released at $col x $row (mods: $modifier)"
fi
done < "${1:-/dev/stdin}"
|