Implemented mouse support toggle

This commit is contained in:
Luxferre
2023-04-02 18:18:10 +03:00
parent 3543983ca1
commit eefa9167ba
2 changed files with 9 additions and 4 deletions
+6 -4
View File
@@ -60,6 +60,7 @@ ALTBUFON="${ESC}[?47h" # use the alternative screen buffer
ALTBUFOFF="${ESC}[?47l" # return to the default screen buffer
# mouse event support switches
MOUSE_ENABLED=1
MOUSEON="${ESC}[?1000;1006h" # term command to start sending mouse input events as control sequences (semi-long format, no drag)
MOUSEOFF="${ESC}[?1000;1006l" # term command to stop sending mouse input events as control sequences (semi-long format, no drag)
# in the semi-long format without drag, every mouse control sequence starts with "${ESC}[<" and then has three fields:
@@ -365,7 +366,7 @@ mouseY=''
mouseStatus='M'
while true; do
mousecmd='' # mouse command buffer
printf '%s' "$MOUSEON" # enable mouse events before reading
[[ "$MOUSE_ENABLED" == '1' ]] && printf '%s' "$MOUSEON" # enable mouse events before reading
read -n 1 -s cmdbuf # read the character, tildas will be ignored
if [[ "$cmdbuf" == $'\x1b' ]]; then # here's the control character
read -n 2 -s cmdbuf # read 2 additional characters
@@ -373,7 +374,7 @@ while true; do
read -r -s mousecmd mouseX mouseY mouseStatus < <(readmouseinput)
fi
fi
printf '%s' "$MOUSEOFF" # don't generate mouse events outside the input sequence
[[ "$MOUSE_ENABLED" == '1' ]] && printf '%s' "$MOUSEOFF" # don't generate mouse events outside the input sequence
[[ "$mousecmd" == '2' && "$mouseStatus" == 'M' ]] && cmdbuf='b' # right click is automatically assigned to back command
[[ "$cmdbuf" == '[A' || "$cmdbuf" == 'k' || "$mousecmd" == '64' ]] && scroll -1
[[ "$cmdbuf" == '[B' || "$cmdbuf" == 'j' || "$mousecmd" == '65' ]] && scroll 1
@@ -387,6 +388,7 @@ while true; do
[[ "$cmdbuf" == 'd' ]] && clicklink 1 # same as click but with force-download flag
[[ "$cmdbuf" == 'b' ]] && goback
[[ "$cmdbuf" == 'S' ]] && stashlink
[[ "$mousecmd" == '0' && "$mouseStatus" == 'M' ]] && mouseclick $mouseX $mouseY # we only process left click with coordinates here
[[ "$mousecmd" == '1' && "$mouseStatus" == 'M' ]] && mouseclick $mouseX $mouseY 1 # we only process middle click with coordinates here
[[ "$cmdbuf" == 'm' ]] && MOUSE_ENABLED=$(( 1 - MOUSE_ENABLED ))
[[ "$MOUSE_ENABLED" == '1' && "$mousecmd" == '0' && "$mouseStatus" == 'M' ]] && mouseclick $mouseX $mouseY # we only process left click with coordinates here
[[ "$MOUSE_ENABLED" == '1' && "$mousecmd" == '1' && "$mouseStatus" == 'M' ]] && mouseclick $mouseX $mouseY 1 # we only process middle click with coordinates here
done