diff --git a/install/provisioning/setup-form.sh b/install/provisioning/setup-form.sh index 9d8bd0d2..101f3468 100644 --- a/install/provisioning/setup-form.sh +++ b/install/provisioning/setup-form.sh @@ -17,10 +17,7 @@ # only keys any gum widget exits on, and Ctrl+C arrives as a byte in raw mode, # so it never reaches the shell as SIGINT. Act on the status, never on a trap. # -# Callers supply `notice ` for validation feedback, and set -# the variables these prompts write: region, keyboard, keyboard_label, -# username, password, password_confirmation, full_name, email_address, -# hostname, timezone. +# Callers supply `notice ` and set every variable these prompts write. OMARCHY_FORM_BACK=1 OMARCHY_FORM_SIGNAL=130 @@ -95,7 +92,7 @@ omarchy_username_taken() { return 1; } # China lists the .cn package mirrors first and sets up Chinese input. omarchy_prompt_region() { local choice status - choice=$(gum choose --selected "Global" --header "Select region" Global China) && status=0 || status=$? + choice=$(printf '%s\n' Global China | gum choose --selected "${region^}" --header "Select region") && status=0 || status=$? ((status == 0)) || return $status region=${choice,,} diff --git a/test/shell.d/setup-form-test.sh b/test/shell.d/setup-form-test.sh index 3e5ff777..1dc7ccdc 100755 --- a/test/shell.d/setup-form-test.sh +++ b/test/shell.d/setup-form-test.sh @@ -53,6 +53,8 @@ source "$ROOT/install/provisioning/setup-form.sh" notice() { printf '%s\n' "$1" >>"$NOTICES"; } +region=${REGION:-global} + if [[ -n ${TAKEN_USERS:-} ]]; then omarchy_username_taken() { [[ " $TAKEN_USERS " == *" $1 "* ]]; } fi @@ -129,10 +131,12 @@ pass "the form publishes the 0/1/130 status contract and leads with English (US) run_prompt omarchy_prompt_region "0:China" assert_status 0 "region prompt succeeds" [[ $(field region) == "china" ]] || fail "region prompt stores China as china" -grep -qxF -- 'choose --selected Global --header Select region Global China' "$GUM_ARGS" || fail "region prompt offers Global then China and preselects Global" -run_prompt omarchy_prompt_region "0:Global" +[[ $(<"$tmp_dir/stdin.1") == $'Global\nChina' ]] || fail "region prompt offers Global then China" +grep -qxF -- 'choose --selected Global --header Select region' "$GUM_ARGS" || fail "region prompt preselects Global on a fresh form" +REGION=china run_prompt omarchy_prompt_region "0:Global" [[ $(field region) == "global" ]] || fail "region prompt stores Global as global" -pass "region prompt maps Global and China to the stored region" +grep -qxF -- 'choose --selected China --header Select region' "$GUM_ARGS" || fail "region prompt preselects the region chosen on an earlier visit" +pass "region prompt maps Global and China and preselects the current region" run_prompt omarchy_prompt_region "1:" assert_status "$OMARCHY_FORM_BACK" "region prompt reports Esc as back"