Implemented mouse support toggle
This commit is contained in:
@@ -76,6 +76,7 @@ No. Besides the ambiguity problem, it will also introduce huge external dependen
|
|||||||
- Go back: b or right mouse click anywhere (if supported)
|
- Go back: b or right mouse click anywhere (if supported)
|
||||||
- Refresh the page: r
|
- Refresh the page: r
|
||||||
- Stash the link to the currently open resource: S (shift+s)
|
- Stash the link to the currently open resource: S (shift+s)
|
||||||
|
- Toggle mouse support (always on when starting): m
|
||||||
- Quit the browser: q
|
- Quit the browser: q
|
||||||
|
|
||||||
## What is the link stash?
|
## What is the link stash?
|
||||||
@@ -110,6 +111,8 @@ Bopher-NG's mouse input is supported on any terminals that support the 1000 **an
|
|||||||
|
|
||||||
Note that, unlike clipboard, this support is required at the client side only. For instance, you can safely run `bopher-ng.sh` on any compatible Bash version in an SSH session on your terminal and still be able to use mouse there.
|
Note that, unlike clipboard, this support is required at the client side only. For instance, you can safely run `bopher-ng.sh` on any compatible Bash version in an SSH session on your terminal and still be able to use mouse there.
|
||||||
|
|
||||||
|
If you don't want to use mouse capture (for instance, to be able to select and copy things with the terminal app itself), you can temporarily turn off mouse support (and then turn it back on) using the m key.
|
||||||
|
|
||||||
## What is the license on this?
|
## What is the license on this?
|
||||||
|
|
||||||
Fully public domain.
|
Fully public domain.
|
||||||
|
|||||||
+6
-4
@@ -60,6 +60,7 @@ ALTBUFON="${ESC}[?47h" # use the alternative screen buffer
|
|||||||
ALTBUFOFF="${ESC}[?47l" # return to the default screen buffer
|
ALTBUFOFF="${ESC}[?47l" # return to the default screen buffer
|
||||||
|
|
||||||
# mouse event support switches
|
# 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)
|
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)
|
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:
|
# 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'
|
mouseStatus='M'
|
||||||
while true; do
|
while true; do
|
||||||
mousecmd='' # mouse command buffer
|
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
|
read -n 1 -s cmdbuf # read the character, tildas will be ignored
|
||||||
if [[ "$cmdbuf" == $'\x1b' ]]; then # here's the control character
|
if [[ "$cmdbuf" == $'\x1b' ]]; then # here's the control character
|
||||||
read -n 2 -s cmdbuf # read 2 additional characters
|
read -n 2 -s cmdbuf # read 2 additional characters
|
||||||
@@ -373,7 +374,7 @@ while true; do
|
|||||||
read -r -s mousecmd mouseX mouseY mouseStatus < <(readmouseinput)
|
read -r -s mousecmd mouseX mouseY mouseStatus < <(readmouseinput)
|
||||||
fi
|
fi
|
||||||
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
|
[[ "$mousecmd" == '2' && "$mouseStatus" == 'M' ]] && cmdbuf='b' # right click is automatically assigned to back command
|
||||||
[[ "$cmdbuf" == '[A' || "$cmdbuf" == 'k' || "$mousecmd" == '64' ]] && scroll -1
|
[[ "$cmdbuf" == '[A' || "$cmdbuf" == 'k' || "$mousecmd" == '64' ]] && scroll -1
|
||||||
[[ "$cmdbuf" == '[B' || "$cmdbuf" == 'j' || "$mousecmd" == '65' ]] && 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" == 'd' ]] && clicklink 1 # same as click but with force-download flag
|
||||||
[[ "$cmdbuf" == 'b' ]] && goback
|
[[ "$cmdbuf" == 'b' ]] && goback
|
||||||
[[ "$cmdbuf" == 'S' ]] && stashlink
|
[[ "$cmdbuf" == 'S' ]] && stashlink
|
||||||
[[ "$mousecmd" == '0' && "$mouseStatus" == 'M' ]] && mouseclick $mouseX $mouseY # we only process left click with coordinates here
|
[[ "$cmdbuf" == 'm' ]] && MOUSE_ENABLED=$(( 1 - MOUSE_ENABLED ))
|
||||||
[[ "$mousecmd" == '1' && "$mouseStatus" == 'M' ]] && mouseclick $mouseX $mouseY 1 # we only process middle click with coordinates here
|
[[ "$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
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user