Quiet dnf transactions: spinner + one-line summary, log on failure
ui_quiet_run wraps every install_packages/install_optional/group install/remove and the system update: while gum is available and the run is interactive, dnf output is hidden behind a spinner, then a single 'Installing: <pkgs> (N packages)' line. Full output is appended to $SETUP_DNF_LOG (/tmp/fedora-setup-dnf-<uid>.log); on failure the last 20 lines print in red so nothing is lost. Unattended and no-gum runs keep plain full output (logs/cron contract). Also: fallback ui_choose accepts 'x' to exit (muscle memory from the old menu), fixed a stray stdout newline leaking into captured answers (same class as the earlier '\nno' bug), fixed pluralization. Harness: piped fallback, pty gum run incl. a failing VirtualBox pick (red failure + log tail, menu survives, subsequent qemu install ok), unattended regression.
This commit is contained in:
@@ -16,16 +16,7 @@ if [[ -n "${_SB_UI_LOADED:-}" ]]; then
|
||||
fi
|
||||
_SB_UI_LOADED=1
|
||||
|
||||
have_gum() {
|
||||
command -v gum >/dev/null 2>&1 || return 1
|
||||
# stdin must be interactive — it is inherited by $(...) subshells, so
|
||||
# menus still get the real terminal. stdout must NOT be checked: it is
|
||||
# a pipe by definition inside $(ui_choose ...). gum draws its UI on
|
||||
# /dev/tty and prints only the answer to stdout (which we capture).
|
||||
[ -t 0 ] || return 1
|
||||
[ -w /dev/tty ] || return 1
|
||||
return 0
|
||||
}
|
||||
# have_gum lives in lib/common.sh (install_packages needs it too).
|
||||
|
||||
# Single choice from a list.
|
||||
# ui_choose "<header>" "<prompt>" "<default>" item1 item2 ...
|
||||
@@ -62,7 +53,8 @@ ui_choose() {
|
||||
local n=${#items[@]} answer
|
||||
while true; do
|
||||
if ! read -t 90 -rp "$prompt [1-$n] (default: shown above): " answer; then
|
||||
printf "\n"; answer=""
|
||||
printf "\n" >&2
|
||||
answer=""
|
||||
fi
|
||||
# empty/timeout -> the default item (its position in the list)
|
||||
if [[ -z "$answer" ]]; then
|
||||
@@ -74,6 +66,10 @@ ui_choose() {
|
||||
echo "${items[-1]}"
|
||||
return 0
|
||||
fi
|
||||
if [[ "${answer,,}" == "x" ]]; then
|
||||
echo "$default"
|
||||
return 0
|
||||
fi
|
||||
if [[ "$answer" =~ ^[0-9]+$ ]] && (( answer >= 1 && answer <= n )); then
|
||||
echo "${items[$((answer-1))]}"
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user