#!/usr/bin/env bash # The installer's look: the original TUI's palette, splash and [OK] glyphs (installer/data/ # theme.json), in plain bash so nothing has to be built first. Colour and motion need a terminal; # piped or with NO_COLOR it falls back to plain lines. if [[ -n "${CAELESTIA_LOG_LOADED:-}" ]]; then return 0 fi CAELESTIA_LOG_LOADED=1 if [[ -t 1 && -z "${NO_COLOR:-}" ]]; then rgb() { printf '\033[38;2;%d;%d;%dm' "0x${1:0:2}" "0x${1:2:2}" "0x${1:4:2}"; } C_ACCENT=$(rgb 6ae5e1) C_PRIMARY=$(rgb 9bd0cc) C_MUTED=$(rgb 6d7876) C_TEXT=$(rgb dce8e6) C_OK=$(rgb b5ccba) C_WARN=$(rgb e8c87a) C_ERR=$(rgb fa746f) C_BOLD=$'\033[1m' C_OFF=$'\033[0m' else C_ACCENT='' C_PRIMARY='' C_MUTED='' C_TEXT='' C_OK='' C_WARN='' C_ERR='' C_BOLD='' C_OFF='' fi info() { printf ' %s[INFO]%s %s\n' "$C_PRIMARY" "$C_OFF" "$*"; } ok() { printf ' %s[OK]%s %s\n' "$C_OK" "$C_OFF" "$*"; } warn() { printf ' %s[WARN]%s %s\n' "$C_WARN" "$C_OFF" "$*"; } skip() { printf ' %s[SKIP] %s%s\n' "$C_MUTED" "$*" "$C_OFF"; } err() { printf ' %s[ERR]%s %s\n' "$C_ERR" "$C_OFF" "$*" >&2; } die() { err "$*"; exit 1; } # theme.json's splash. ui_banner() { local line printf '\n%s' "$C_ACCENT" while IFS= read -r line; do printf ' %s\n' "$line"; done <<'ART' _____ _ _ _ / ____| | | | | (_) | | __ _ ___ | | ___ ___| |_ _ __ _ | | / _` |/ _ \| |/ _ \/ __| __| |/ _` | | |___| (_| | (_) | | __/\__ \ |_| | (_| | \_____\__,_|\___/|_|\___||___/\__|_|\__,_| ART printf '%s\n %sfor niri%s\n\n' "$C_OFF" "$C_MUTED" "$C_OFF" } # A step's heading: ui_step 2 4 "Building the shell" ui_step() { local width=$(( ${COLUMNS:-$(tput cols 2>/dev/null || echo 72)} - 4 )) ((width > 72)) && width=72 local rule title=" $3 " printf -v rule '%*s' "$((width - ${#title} - 8))" '' printf '\n %s──%s %s[%s/%s]%s%s%s %s%s%s\n\n' "$C_MUTED" "$C_OFF" "$C_ACCENT" "$1" "$2" "$C_OFF" "$C_BOLD$C_TEXT" "$title" "$C_OFF$C_MUTED" "${rule// /─}" "$C_OFF" } # Runs a command with its output in the log and a spinner on screen. Ends with [OK], or with the # log's tail and the command's status. ui_run() { local title="$1" log="${CAELESTIA_LOG:-/tmp/caelestia-niri-install.log}" shift if [[ ! -t 1 ]]; then info "$title" "$@" >>"$log" 2>&1 && { ok "$title"; return 0; } else "$@" >>"$log" 2>&1 & local pid=$! frame=0 start=$SECONDS frames='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏' while kill -0 "$pid" 2>/dev/null; do printf '\r %s%s%s %s %s%ds%s\033[K' "$C_ACCENT" "${frames:frame++ % 10:1}" "$C_OFF" "$title" "$C_MUTED" "$((SECONDS - start))" "$C_OFF" sleep 0.1 done printf '\r\033[K' wait "$pid" && { ok "$title ($((SECONDS - start))s)"; return 0; } fi local status=$? err "$title failed. The end of $log:" tail -n 15 "$log" | sed 's/^/ /' >&2 return "$status" } # A checklist on the terminal: ui_checklist "Heading" label... prints the indices kept, one a line. # All start ticked. Up and Down move, Space ticks, a and n set all or none, Enter accepts. With # --yes or no terminal it keeps everything. ui_checklist() { local heading="$1" count=$(($# - 1)) i shift local labels=("$@") on=() at=0 key rest for ((i = 0; i < count; i++)); do on[i]=1; done if [[ "${ASSUME_YES:-0}" == 1 || ! -r /dev/tty || ! -t 1 && ! -c /dev/tty ]] || ! { : /dev/null; then for ((i = 0; i < count; i++)); do echo "$i"; done return 0 fi { printf ' %s%s%s\n' "$C_TEXT" "$heading" "$C_OFF" printf ' %sUp/Down move, Space ticks, a all, n none, Enter accepts%s\n' "$C_MUTED" "$C_OFF" printf '\033[?25l' trap 'printf "\033[?25h" >/dev/tty' EXIT while :; do for ((i = 0; i < count; i++)); do local mark="[ ]" tint="$C_MUTED" arrow=" " if ((on[i])); then mark="[x]" tint="$C_TEXT"; fi if ((i == at)); then arrow="$C_ACCENT>$C_OFF"; fi printf ' %s %s %s%s%s\033[K\n' "$arrow" "$mark" "$tint" "${labels[i]}" "$C_OFF" done IFS= read -rsn1 key /dev/tty for ((i = 0; i < count; i++)); do if ((on[i])); then echo "$i"; fi done }