From 20fbadbc9561dd169ecedb9cb4435b36a29108e9 Mon Sep 17 00:00:00 2001 From: Felitendo Date: Sat, 8 Aug 2026 14:58:28 +0200 Subject: [PATCH] Menu: act on a single keypress instead of waiting for Enter Also stops Enter from quitting the menu (it used to share the quit branch with q) and swallows the tail of an escape sequence, so one arrow key redraws once rather than three times and never closes the menu. --- Makefile | 2 +- po/cachy-auto-update.pot | 2 +- po/de.po | 4 ++-- src/lib/menu.sh | 21 +++++++++++++++++---- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 8429e86..2567a4c 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ # Overridable so a packager can pass the version it is actually building # (`make VERSION=$pkgver`). The literal below is the fallback for builds # straight from a checkout, and is what a release tag has to carry. -VERSION ?= 1.0.2 +VERSION ?= 1.0.3 PREFIX ?= /usr DESTDIR ?= diff --git a/po/cachy-auto-update.pot b/po/cachy-auto-update.pot index 44bbd6d..059d20f 100644 --- a/po/cachy-auto-update.pot +++ b/po/cachy-auto-update.pot @@ -134,7 +134,7 @@ msgstr "" msgid "Quit" msgstr "" -msgid "Press Enter to continue..." +msgid "Press any key to continue..." msgstr "" #. Commands diff --git a/po/de.po b/po/de.po index 0102ab7..631c74e 100644 --- a/po/de.po +++ b/po/de.po @@ -135,8 +135,8 @@ msgstr "Aktuelle Bedingungen anzeigen" msgid "Quit" msgstr "Beenden" -msgid "Press Enter to continue..." -msgstr "Zum Fortfahren Enter drücken …" +msgid "Press any key to continue..." +msgstr "Zum Fortfahren eine Taste drücken …" #. Commands msgid "Automatic updates are on." diff --git a/src/lib/menu.sh b/src/lib/menu.sh index 72f77e4..55c5337 100644 --- a/src/lib/menu.sh +++ b/src/lib/menu.sh @@ -145,7 +145,11 @@ cau_ui_menu() { printf ' [q] %s\n' "$(cau_msg "Quit")" printf '\n > ' - read -r choice || { printf '\n'; return 0; } + # One keypress, no Enter. -s keeps the raw character out of the + # display so the echo below is the only thing printed, and a failing + # read means EOF (Ctrl-D, or a script piping input) - that quits. + read -rsn1 choice || { printf '\n'; return 0; } + printf '%s\n' "$choice" case "$choice" in 1) @@ -163,13 +167,22 @@ cau_ui_menu() { 3) cau_do_run --force; cau_pause ;; 4) cau_do_log; cau_pause ;; 5) cau_ui_status_conditions; cau_pause ;; - q|Q|'') return 0 ;; + q|Q) return 0 ;; + $'\e') + # Arrow keys and friends arrive as ESC [ X. Swallow the rest so + # one keypress does not redraw the menu three times. Escape is + # deliberately not a quit key: that would make a stray arrow + # key close the menu. + read -rsn2 -t 0.05 _ 2>/dev/null || true + ;; + # Anything else, Enter included, just redraws. *) ;; esac done } cau_pause() { - printf '\n %s' "$(cau_msg "Press Enter to continue...")" - read -r _ || true + printf '\n %s' "$(cau_msg "Press any key to continue...")" + read -rsn1 _ || true + printf '\n' }