phoebus_os/installer/tui/ui.sh
Phoebus 38214ea9e7 chore: import Phoebus OS installer and Rust migration
Initial public import of the proven Bash installer (installer/) and the production Rust workspace (installer-rs/). The reference ISO, build output and local agent transcripts are gitignored.

Verified: installer/tests/run_tests.sh and cargo test --workspace both pass.
2026-09-20 02:07:33 -07:00

127 lines
3.2 KiB
Bash

#!/usr/bin/env bash
# shellcheck shell=bash
#
# Thin TUI wrapper around dialog/whiptail.
#
# dialog is the preferred backend (present in the Gentoo LiveGUI reference).
# whiptail is accepted as a fallback so the installer also works in minimal
# environments. Only the common option subset is used.
#
# All functions store the result in UI_RESULT and return 0 on OK / 1 on cancel.
declare -g UI_BACKEND="${UI_BACKEND:-auto}"
declare -g UI_RESULT="${UI_RESULT:-}"
declare -g UI_TITLE="${UI_TITLE:-}"
ui_init() {
if [[ "$UI_BACKEND" == "auto" ]]; then
if command -v dialog >/dev/null 2>&1; then
UI_BACKEND="dialog"
elif command -v whiptail >/dev/null 2>&1; then
UI_BACKEND="whiptail"
else
UI_BACKEND="none"
fi
fi
UI_TITLE="${DISTRO_NAME:-Phoebus OS} Installer"
[[ "$UI_BACKEND" == "none" ]] && return 1
return 0
}
ui_available() { [[ "$UI_BACKEND" != "none" ]]; }
_ui() {
case "$UI_BACKEND" in
dialog) dialog "$@" ;;
whiptail) whiptail "$@" ;;
*) return 127 ;;
esac
}
# _ui_capture ARGS... - run and put textual result in UI_RESULT
_ui_capture() {
local f rc
f="$(mktemp "${TMPDIR:-/tmp}/phoebus-ui.XXXXXX")" || return 1
_ui --output-fd 3 "$@" 3>"$f"
rc=$?
UI_RESULT="$(cat "$f")"
rm -f "$f"
case "$rc" in
0) return 0 ;;
*) return 1 ;;
esac
}
ui_backtitle_args() {
printf '%s\n' --backtitle "$UI_TITLE"
}
ui_msgbox() {
local title="$1" text="$2"
_ui --title "$title" --backtitle "$UI_TITLE" --msgbox "$text" 0 0
}
ui_yesno() {
local title="$1" text="$2"
_ui --title "$title" --backtitle "$UI_TITLE" --yesno "$text" 0 0
}
ui_inputbox() {
local title="$1" text="$2" init="${3-}"
_ui_capture --title "$title" --backtitle "$UI_TITLE" --inputbox "$text" 0 0 "$init"
}
ui_passwordbox() {
local title="$1" text="$2"
if [[ "$UI_BACKEND" == "dialog" ]]; then
_ui_capture --title "$title" --backtitle "$UI_TITLE" --insecure --passwordbox "$text" 0 0
else
_ui_capture --title "$title" --backtitle "$UI_TITLE" --passwordbox "$text" 0 0
fi
}
ui_menu() {
local title="$1" text="$2" height="$3" width="$4" listheight="$5"
shift 5
_ui_capture --title "$title" --backtitle "$UI_TITLE" \
--menu "$text" "$height" "$width" "$listheight" "$@"
}
ui_radiolist() {
local title="$1" text="$2" height="$3" width="$4" listheight="$5"
shift 5
_ui_capture --title "$title" --backtitle "$UI_TITLE" \
--radiolist "$text" "$height" "$width" "$listheight" "$@"
}
ui_checklist() {
local title="$1" text="$2" height="$3" width="$4" listheight="$5"
shift 5
_ui_capture --title "$title" --backtitle "$UI_TITLE" \
--checklist "$text" "$height" "$width" "$listheight" "$@"
}
ui_textbox() {
local title="$1" file="$2"
_ui --title "$title" --backtitle "$UI_TITLE" --textbox "$file" 0 0
}
ui_infobox() {
local title="$1" text="$2"
_ui --title "$title" --backtitle "$UI_TITLE" --infobox "$text" 0 0
return 0
}
# ui_pause - wait for the user to acknowledge a message
ui_pause() {
ui_msgbox "${1:-Information}" "${2:-Press OK to continue.}"
}
# ui_error - show an error with the log location
ui_error() {
local message="$1"
ui_msgbox "Error" "$message
See the log for details:
$PHOEBUS_LOG_FILE"
}