Skip to content

Commit e64adab

Browse files
committed
Fix menu requiring double input on Alpine (#38)
read -rsn1 in press_any_key consumes only 1 byte. Multi-byte keys (arrows, function keys) send escape sequences (e.g. \033[A) — the remaining bytes leak into stdin and get picked up by the next read_choice, matching no menu option and causing a silent redraw. Fix: drain leftover bytes after every read -rsn1 and defensively at the top of read_choice before accepting user input.
1 parent 408b9c8 commit e64adab

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

mtproxymax.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ draw_sparkline() {
282282
read_choice() {
283283
local prompt="${1:-choice}"
284284
local default="${2:-}"
285+
# Drain any stale input (e.g., leftover escape-sequence bytes)
286+
read -rsn 256 -t 0.05 _ 2>/dev/null || true
285287
echo -en "\n ${DIM}Enter ${prompt,,}${NC}" >&2
286288
[ -n "$default" ] && echo -en " ${DIM}[${default}]${NC}" >&2
287289
echo -en "${DIM}:${NC} " >&2
@@ -307,6 +309,8 @@ press_any_key() {
307309
echo ""
308310
echo -en " ${DIM}Press any key to continue...${NC}"
309311
read -rsn1
312+
# Drain leftover bytes from multi-byte keys (arrow/function keys send escape sequences)
313+
read -rsn 256 -t 0.05 _ 2>/dev/null || true
310314
echo ""
311315
}
312316

@@ -4516,6 +4520,7 @@ run_installer() {
45164520
echo ""
45174521
echo -en " ${DIM}Press any key to open the management menu...${NC}"
45184522
read -rsn1
4523+
read -rsn 256 -t 0.05 _ 2>/dev/null || true
45194524
load_settings
45204525
load_secrets
45214526
show_main_menu

0 commit comments

Comments
 (0)