mirror of
https://github.com/tw93/Mole.git
synced 2026-02-12 14:36:20 +00:00
fix: extend ESC sequence timeout and avoid accidental quit on any key
This commit is contained in:
@@ -106,11 +106,11 @@ read_key() {
|
|||||||
'?') echo "HELP" ;;
|
'?') echo "HELP" ;;
|
||||||
$'\x7f'|$'\b') echo "BACKSPACE" ;; # Support Backspace
|
$'\x7f'|$'\b') echo "BACKSPACE" ;; # Support Backspace
|
||||||
$'\x1b')
|
$'\x1b')
|
||||||
# Non-blocking, byte-by-byte escape sequence parsing to avoid leaking 'A'/'B'
|
# ESC sequence handling. Allow slightly longer window so we don't misinterpret slow terminals.
|
||||||
local next third
|
local next third
|
||||||
if IFS= read -r -s -n 1 -t 0.02 next 2>/dev/null; then
|
if IFS= read -r -s -n 1 -t 0.15 next 2>/dev/null; then
|
||||||
if [[ "$next" == "[" ]]; then
|
if [[ "$next" == "[" ]]; then
|
||||||
if IFS= read -r -s -n 1 -t 0.02 third 2>/dev/null; then
|
if IFS= read -r -s -n 1 -t 0.15 third 2>/dev/null; then
|
||||||
case "$third" in
|
case "$third" in
|
||||||
'A') echo "UP" ;;
|
'A') echo "UP" ;;
|
||||||
'B') echo "DOWN" ;;
|
'B') echo "DOWN" ;;
|
||||||
@@ -119,15 +119,16 @@ read_key() {
|
|||||||
*) echo "OTHER" ;;
|
*) echo "OTHER" ;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
|
# ESC [ then timeout – treat as OTHER to ignore
|
||||||
echo "OTHER"
|
echo "OTHER"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# ESC followed by something else (e.g. ALT key combos)
|
# ESC + something (Alt modified key) → ignore as OTHER
|
||||||
echo "OTHER"
|
echo "OTHER"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Bare ESC = quit
|
# Bare ESC alone: instead of quitting directly, emit OTHER so user doesn't exit accidentally
|
||||||
echo "QUIT"
|
echo "OTHER"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*) echo "OTHER" ;;
|
*) echo "OTHER" ;;
|
||||||
|
|||||||
Reference in New Issue
Block a user