#!/usr/bin/env bash TUI_FS_ACTIVE=0 TUI_FS_ROWS=0 TUI_FS_COLS=0 TUI_FS_LOG_AREA=4 TUI_FS_OVERALL_CURRENT=0 TUI_FS_OVERALL_TOTAL=0 TUI_FS_MODULE_LABEL="" TUI_FS_MODULE_PROGRESS=0 TUI_FS_SAVED_STTY="" tui_fs_init() { ((OMERON_HAS_GUM)) || return 1 TUI_FS_SAVED_STTY=$(stty -g 2>/dev/null || true) TUI_FS_ROWS=$(tput lines 2>/dev/null || echo 24) TUI_FS_COLS=$(tput cols 2>/dev/null || echo 80) TUI_FS_LOG_AREA=4 tput smcup 2>/dev/null tput civis 2>/dev/null tput csr "$TUI_FS_LOG_AREA" $((TUI_FS_ROWS - 1)) 2>/dev/null tput clear 2>/dev/null _tui_fs_draw_frame TUI_FS_ACTIVE=1 trap '_tui_fs_cleanup' EXIT INT TERM tput cup "$TUI_FS_LOG_AREA" 0 } tui_fs_exit() { [[ "$TUI_FS_ACTIVE" -eq 0 ]] && return TUI_FS_ACTIVE=0 trap - EXIT INT TERM tput csr 0 $((TUI_FS_ROWS - 1)) 2>/dev/null tput cnorm 2>/dev/null tput rmcup 2>/dev/null [[ -n "$TUI_FS_SAVED_STTY" ]] && stty "$TUI_FS_SAVED_STTY" 2>/dev/null || true } tui_fs_set_overall() { TUI_FS_OVERALL_CURRENT=$1 TUI_FS_OVERALL_TOTAL=$2 TUI_FS_MODULE_LABEL="${3:-}" TUI_FS_MODULE_PROGRESS=0 _tui_fs_draw_header } tui_fs_set_progress() { TUI_FS_MODULE_PROGRESS=$1 _tui_fs_draw_header } _tui_fs_cleanup() { tui_fs_exit } _tui_fs_draw_frame() { local cols=$TUI_FS_COLS tput cup 0 0 printf "\033[7m %-*s\033[0m" $((cols - 2)) " Omeron — Modular System Setup" tput cup 1 0 printf " %-*s" $((cols - 3)) "" tput cup 2 0 printf " %-*s" $((cols - 3)) "" tput cup 3 0 printf " " printf '%*s' $((cols - 4)) '' | tr ' ' '─' } _tui_fs_draw_header() { [[ "$TUI_FS_ACTIVE" -eq 0 ]] && return 0 tput sc local cols=$TUI_FS_COLS # Row 1: module label + overall progress tput cup 1 0 printf " " if [[ -n "$TUI_FS_MODULE_LABEL" ]]; then printf "Module: %-*s" $((cols - 35)) "$TUI_FS_MODULE_LABEL" if ((TUI_FS_OVERALL_TOTAL > 0)); then printf " [%d/%d]" "$TUI_FS_OVERALL_CURRENT" "$TUI_FS_OVERALL_TOTAL" fi fi tput el # Row 2: progress bar tput cup 2 0 printf " " local bar_width=$((cols - 16)) ((bar_width < 10)) && bar_width=10 local progress=0 if ((TUI_FS_OVERALL_TOTAL > 0)); then local overall_pct=$((TUI_FS_OVERALL_CURRENT * 100 / TUI_FS_OVERALL_TOTAL)) if ((TUI_FS_OVERALL_TOTAL == TUI_FS_OVERALL_CURRENT)) && ((TUI_FS_MODULE_PROGRESS >= 100)); then progress=100 else local module_share=$((100 / TUI_FS_OVERALL_TOTAL)) local completed_pct=$(( (TUI_FS_OVERALL_CURRENT - 1) * 100 / TUI_FS_OVERALL_TOTAL )) local current_pct=$(( TUI_FS_MODULE_PROGRESS * module_share / 100 )) progress=$((completed_pct + current_pct)) ((progress > 100)) && progress=100 fi fi local filled=$(( progress * bar_width / 100 )) local i for ((i=0; i&2 } tui_fs_log_error() { printf ' \033[1;31m✗\033[0m %s\n' "$1" >&2 } tui_fs_log_section() { local msg="$1" local line printf -v line '%*s' "${#msg}" '' && line="${line// /─}" printf ' %s\n' "$line" printf ' %s\n' "$msg" printf ' %s\n' "$line" }