fix: Interactive checkbox menu: arrow keys to move, Space to select, Enter to run

Falls back to the numbered prompt when input is not a terminal, so
scripted test runs keep working.
This commit is contained in:
theupriser committed 2026-09-23 15:25:25 +02:00
1 parent b91fa4bc83
commit 3d7f3764d6
3 files changed
+75 -15

No files matched your search

+2 -1
View File
@@ -109,7 +109,8 @@ shellcheck -S warning setup-gamescope-boot.sh lib/*.sh # if available
Behaviour is verified in a CachyOS QEMU/KVM test VM. The VM scripts and a Behaviour is verified in a CachyOS QEMU/KVM test VM. The VM scripts and a
Claude Code skill describing the whole test workflow (snapshots, SSH, running Claude Code skill describing the whole test workflow (snapshots, SSH, running
the wizard with scripted menu input such as `printf '2\n\ny\nn\n'`, the the wizard with scripted menu input such as `printf '2\n\ny\nn\n'`, the
per-component checks, reboot checks, the full test matrix, `--fremont` to per-component checks; when stdin is not a terminal the menu falls back to a
numbered prompt, which is what scripted runs use, reboot checks, the full test matrix, `--fremont` to
fake Steam Machine hardware) live in fake Steam Machine hardware) live in
[cachyos-gamescope-boot-dev-env](https://github.com/theupriser/cachyos-gamescope-boot-dev-env). [cachyos-gamescope-boot-dev-env](https://github.com/theupriser/cachyos-gamescope-boot-dev-env).
Gamescope itself and the real LED bar can only be verified on hardware. Gamescope itself and the real LED bar can only be verified on hardware.
+12 -12
View File
@@ -43,24 +43,24 @@ cd <this-repo>
./setup-gamescope-boot.sh ./setup-gamescope-boot.sh
``` ```
Run it as yourself, not as root. You'll see a menu like this: Run it as yourself, not as root. You'll see a checklist:
``` ```
# Now Want Component [x] SteamOS conversion: boot into gaming mode, Steam on the desktop (now: off)
1 off [x] SteamOS conversion: boot into gaming mode, Steam on the desktop > [x] Install SteamOS theme: Vapor look, dark mode, SteamOS taskbar (now: off)
2 off [x] Install SteamOS theme: Vapor look, dark mode, SteamOS taskbar [x] Install Steam Deck/Machine icons: Deck button icons in gaming mode (now: off)
3 off [x] Install Steam Deck/Machine icons: Deck button icons in gaming mode [x] Single user mode: no password, lock screen or log out (SDDM) (now: off)
4 off [x] Single user mode: no password, lock screen or log out (SDDM)
Up/Down move Space select Enter run a run + re-apply what's on q quit
``` ```
**Now** shows what's on at the moment, **Want** what you'd like. Type a Move with the **arrow keys**, tick or untick with **Space**, and press
number and press Enter to tick or untick it, then press Enter on an empty **Enter** to run. "now:" shows what's on at the moment. The wizard then
line to continue. The wizard shows what it will change, asks your password shows what it will change, asks your password once, and at the end offers
once, and at the end offers to restart (needed for changes to how the PC to restart (needed for changes to how the PC starts).
starts).
Run it again whenever you like - to change your choices, to turn things off Run it again whenever you like - to change your choices, to turn things off
again, or after a CachyOS update (type `a` in the menu to re-apply again, or after a CachyOS update (press `a` in the menu to re-apply
everything that's on). everything that's on).
Keep the whole folder: the script needs the files in `lib/` next to it. Keep the whole folder: the script needs the files in `lib/` next to it.
+61 -2
View File
@@ -59,12 +59,71 @@ show_menu() {
} }
run_menu() { run_menu() {
# Sets REAPPLY. Returns 1 if the user quit. # Sets REAPPLY. Returns 1 if the user quit. A checkbox list on a
# terminal; a plain numbered prompt when input is piped (scripted runs).
REAPPLY=false REAPPLY=false
if [[ -t 0 && -t 1 ]]; then
run_menu_tui
else
run_menu_lines
fi
}
draw_menu_tui() {
local cursor="$1" i=0 c box state line
printf '\033[H\033[2J'
echo -e "${c_bold}CachyOS Steam Deck-style Gamescope Boot Wizard${c_reset}"
echo "Pick what you want. Anything you untick is put back the way it was."
echo
MENU_ITEMS=()
for c in "${COMPONENTS[@]}"; do
component_available "$c" || continue
MENU_ITEMS[$i]=$c
box="[ ]"; [[ "${WANTED[$c]}" == 1 ]] && box="[${c_green}x${c_reset}]"
state="off"; [[ "${CURRENT[$c]}" == 1 ]] && state="${c_green}on${c_reset}"
line="$box ${LABEL[$c]}"
if (( i == cursor )); then
echo -e " ${c_cyan}>${c_reset} ${c_bold}${line}${c_reset} (now: ${state})"
else
echo -e " ${line} (now: ${state})"
fi
i=$((i + 1))
done
echo
echo -e " ${c_bold}Up/Down${c_reset} move ${c_bold}Space${c_reset} select ${c_bold}Enter${c_reset} run ${c_bold}a${c_reset} run + re-apply what's on ${c_bold}q${c_reset} quit"
}
run_menu_tui() {
local cursor=0 key rest count
tput civis 2>/dev/null
trap 'tput cnorm 2>/dev/null' EXIT
while true; do
draw_menu_tui "$cursor"
count=${#MENU_ITEMS[@]}
IFS= read -rsn1 key
if [[ "$key" == $'\e' ]]; then
IFS= read -rsn2 -t 0.05 rest
key+="$rest"
fi
case "$key" in
$'\e[A'|k) (( cursor = (cursor + count - 1) % count )) ;;
$'\e[B'|j) (( cursor = (cursor + 1) % count )) ;;
" ") toggle_component "${MENU_ITEMS[$cursor]}" ;;
"") break ;;
a|A) REAPPLY=true; break ;;
q|Q) tput cnorm 2>/dev/null; echo; return 1 ;;
esac
done
tput cnorm 2>/dev/null
echo
return 0
}
run_menu_lines() {
local reply local reply
while true; do while true; do
show_menu show_menu
read -rp "$(echo -e "${c_bold}Type a number to toggle, Enter to continue, a = also re-apply what's on, q = quit:${c_reset} ")" reply read -rp "$(echo -e "${c_bold}Type a number to toggle, Enter to continue, a = also re-apply what's on, q = quit:${c_reset} ")" reply || return 1
case "$reply" in case "$reply" in
"") return 0 ;; "") return 0 ;;
a|A) REAPPLY=true; return 0 ;; a|A) REAPPLY=true; return 0 ;;