Ask for the language, not the region, on the installer's first screen

omarchy_prompt_keyboard takes the layout to preselect.
This commit is contained in:
ZacharyZhang-NY committed 2026-10-09 00:15:06 -04:00
1 parent 848e9610c0
commit e5b01ace6b
2 files changed
+47 -41

No files matched your search

+13 -12
View File
@@ -129,28 +129,29 @@ omarchy_username_taken() { return 1; }
# by `status=$?`: one caller runs under `set -e`, where a cancelled prompt is a # by `status=$?`: one caller runs under `set -e`, where a cancelled prompt is a
# failing assignment that would kill the script before the status is read. # failing assignment that would kill the script before the status is read.
# China lists the .cn mirrors first and sets up Chinese input; its Chinese name shows only in a CJK console. # English or Simplified Chinese; the Chinese name shows only in a CJK console.
omarchy_prompt_region() { omarchy_prompt_language() {
local china="China" header="Select region" selected=Global choice status local chinese="Chinese" header="Select language" selected=English choice status
if [[ -n ${OMARCHY_CJK_CONSOLE:-} ]]; then if [[ -n ${OMARCHY_CJK_CONSOLE:-} ]]; then
china="China 中国" chinese="简体中文 Chinese"
header="Select region · 选择区域" header="Select language · 选择语言"
fi fi
[[ $region == "cn" ]] && selected=$china [[ $language == "zh" ]] && selected=$chinese
choice=$(printf '%s\n' Global "$china" | gum choose --selected "$selected" --header "$header") && status=0 || status=$? choice=$(printf '%s\n' English "$chinese" | gum choose --selected "$selected" --header "$header") && status=0 || status=$?
((status == 0)) || return $status ((status == 0)) || return $status
if [[ $choice == "Global" ]]; then if [[ $choice == "English" ]]; then
region=global language=en
else else
region=cn language=zh
fi fi
} }
# Callers may name the layout to preselect.
omarchy_prompt_keyboard() { omarchy_prompt_keyboard() {
local choice status local choice status selected=${1:-English (US)}
choice=$(printf '%s\n' "$OMARCHY_KEYBOARD_LAYOUTS" | cut -d'|' -f1 | choice=$(printf '%s\n' "$OMARCHY_KEYBOARD_LAYOUTS" | cut -d'|' -f1 |
gum choose --height 10 --selected "English (US)" --header "$(omarchy_text "Select keyboard layout")") && status=0 || status=$? gum choose --height 10 --selected "$selected" --header "$(omarchy_text "Select keyboard layout")") && status=0 || status=$?
((status == 0)) || return $status ((status == 0)) || return $status
local selection local selection
+34 -29
View File
@@ -53,7 +53,7 @@ source "$ROOT/install/provisioning/setup-form.sh"
notice() { printf '%s\n' "$1" >>"$NOTICES"; } notice() { printf '%s\n' "$1" >>"$NOTICES"; }
region=${REGION:-global} language=${FORM_LANGUAGE:-en}
if [[ -n ${TAKEN_USERS:-} ]]; then if [[ -n ${TAKEN_USERS:-} ]]; then
omarchy_username_taken() { [[ " $TAKEN_USERS " == *" $1 "* ]]; } omarchy_username_taken() { [[ " $TAKEN_USERS " == *" $1 "* ]]; }
@@ -61,9 +61,9 @@ fi
trap 'if [[ ${FUNCNAME[0]:-} == "$PROMPT_FN" ]]; then printf "returned\n" >>"$MARKER"; fi' RETURN trap 'if [[ ${FUNCNAME[0]:-} == "$PROMPT_FN" ]]; then printf "returned\n" >>"$MARKER"; fi' RETURN
"$PROMPT_FN" "$PROMPT_FN" ${PROMPT_ARG:+"$PROMPT_ARG"}
printf 'region=%s\n' "${region:-}" printf 'language=%s\n' "${language:-}"
printf 'keyboard=%s\n' "${keyboard:-}" printf 'keyboard=%s\n' "${keyboard:-}"
printf 'keyboard_label=%s\n' "${keyboard_label:-}" printf 'keyboard_label=%s\n' "${keyboard_label:-}"
printf 'keyboard_input_method=%s\n' "${keyboard_input_method:-}" printf 'keyboard_input_method=%s\n' "${keyboard_input_method:-}"
@@ -128,36 +128,36 @@ source "$ROOT/install/provisioning/setup-form.sh"
fail "English (US) leads the keyboard layouts so gum choose opens on the default" fail "English (US) leads the keyboard layouts so gum choose opens on the default"
pass "the form publishes the 0/1/130 status contract and leads with English (US)" pass "the form publishes the 0/1/130 status contract and leads with English (US)"
# Region # Language
run_prompt omarchy_prompt_region "0:China" run_prompt omarchy_prompt_language "0:Chinese"
assert_status 0 "region prompt succeeds" assert_status 0 "language prompt succeeds"
[[ $(field region) == "cn" ]] || fail "region prompt stores China as cn" [[ $(field language) == "zh" ]] || fail "language prompt stores Chinese as zh"
[[ $(<"$tmp_dir/stdin.1") == $'Global\nChina' ]] || fail "region prompt offers Global then China" [[ $(<"$tmp_dir/stdin.1") == $'English\nChinese' ]] || fail "language prompt offers English then Chinese"
grep -qxF -- 'choose --selected Global --header Select region' "$GUM_ARGS" || fail "region prompt preselects Global on a fresh form" grep -qxF -- 'choose --selected English --header Select language' "$GUM_ARGS" || fail "language prompt preselects English on a fresh form"
REGION=cn run_prompt omarchy_prompt_region "0:Global" FORM_LANGUAGE=zh run_prompt omarchy_prompt_language "0:English"
[[ $(field region) == "global" ]] || fail "region prompt stores Global as global" [[ $(field language) == "en" ]] || fail "language prompt stores English as en"
grep -qxF -- 'choose --selected China --header Select region' "$GUM_ARGS" || fail "region prompt preselects the region chosen on an earlier visit" grep -qxF -- 'choose --selected Chinese --header Select language' "$GUM_ARGS" || fail "language prompt preselects the language chosen on an earlier visit"
pass "region prompt maps Global and China and preselects the current region" pass "language prompt maps English and Chinese and preselects the current language"
run_prompt omarchy_prompt_region "1:" run_prompt omarchy_prompt_language "1:"
assert_status "$OMARCHY_FORM_BACK" "region prompt reports Esc as back" assert_status "$OMARCHY_FORM_BACK" "language prompt reports Esc as back"
assert_returned "region prompt survives Esc under set -e" assert_returned "language prompt survives Esc under set -e"
run_prompt omarchy_prompt_region "130:" run_prompt omarchy_prompt_language "130:"
assert_status "$OMARCHY_FORM_SIGNAL" "region prompt reports Ctrl+C as the caller's signal" assert_status "$OMARCHY_FORM_SIGNAL" "language prompt reports Ctrl+C as the caller's signal"
assert_returned "region prompt survives Ctrl+C under set -e" assert_returned "language prompt survives Ctrl+C under set -e"
pass "region prompt propagates Esc and Ctrl+C without dying under set -e" pass "language prompt propagates Esc and Ctrl+C without dying under set -e"
OMARCHY_CJK_CONSOLE=1 run_prompt omarchy_prompt_region "0:China 中国" OMARCHY_CJK_CONSOLE=1 run_prompt omarchy_prompt_language "0:简体中文 Chinese"
assert_status 0 "region prompt succeeds in a CJK console" assert_status 0 "language prompt succeeds in a CJK console"
[[ $(field region) == "cn" ]] || fail "region prompt stores China 中国 as cn" [[ $(field language) == "zh" ]] || fail "language prompt stores 简体中文 as zh"
[[ $(<"$tmp_dir/stdin.1") == $'Global\nChina 中国' ]] || fail "a CJK console offers the Chinese name" [[ $(<"$tmp_dir/stdin.1") == $'English\n简体中文 Chinese' ]] || fail "a CJK console offers the Chinese name"
grep -qxF -- 'choose --selected Global --header Select region · 选择区域' "$GUM_ARGS" || fail "a CJK console asks in both languages" grep -qxF -- 'choose --selected English --header Select language · 选择语言' "$GUM_ARGS" || fail "a CJK console asks in both languages"
OMARCHY_CJK_CONSOLE=1 REGION=cn run_prompt omarchy_prompt_region "0:Global" OMARCHY_CJK_CONSOLE=1 FORM_LANGUAGE=zh run_prompt omarchy_prompt_language "0:English"
[[ $(field region) == "global" ]] || fail "region prompt stores Global as global in a CJK console" [[ $(field language) == "en" ]] || fail "language prompt stores English as en in a CJK console"
grep -qxF -- 'choose --selected China 中国 --header Select region · 选择区域' "$GUM_ARGS" || fail "a CJK console preselects China by its shown name" grep -qxF -- 'choose --selected 简体中文 Chinese --header Select language · 选择语言' "$GUM_ARGS" || fail "a CJK console preselects Chinese by its shown name"
pass "a CJK console names China in Chinese and maps it back to cn" pass "a CJK console names Chinese in Chinese and maps it back to zh"
# Keyboard # Keyboard
@@ -169,6 +169,11 @@ assert_status 0 "keyboard prompt succeeds"
grep -qF -- '--selected English (US)' "$GUM_ARGS" || fail "keyboard prompt preselects English (US)" grep -qF -- '--selected English (US)' "$GUM_ARGS" || fail "keyboard prompt preselects English (US)"
pass "keyboard prompt maps the chosen label to its keymap" pass "keyboard prompt maps the chosen label to its keymap"
PROMPT_ARG="Chinese (Simplified, Pinyin)" run_prompt omarchy_prompt_keyboard "0:Chinese (Simplified, Pinyin)"
grep -qF -- '--selected Chinese (Simplified, Pinyin)' "$GUM_ARGS" && [[ $(field keyboard_input_method) == "pinyin" ]] ||
fail "keyboard prompt preselects the layout its caller names"
pass "keyboard prompt preselects the layout its caller names"
for selection in 'Japanese|jp106|mozc|' 'Japanese (US keyboard)|us|mozc|' 'Korean|us|hangul|kr' 'Chinese (Simplified, Pinyin)|us|pinyin|' 'Chinese (Traditional, Zhuyin)|us|chewing|'; do for selection in 'Japanese|jp106|mozc|' 'Japanese (US keyboard)|us|mozc|' 'Korean|us|hangul|kr' 'Chinese (Simplified, Pinyin)|us|pinyin|' 'Chinese (Traditional, Zhuyin)|us|chewing|'; do
IFS='|' read -r label keymap method layout <<< "$selection" IFS='|' read -r label keymap method layout <<< "$selection"
run_prompt omarchy_prompt_keyboard "0:$label" run_prompt omarchy_prompt_keyboard "0:$label"