Alle Fenster ueber drei gemeinsame Stellen, Selbstpruefung dazu
Die berechnete Fenstergroesse galt bisher nur fuer die Dialoge, die ich
dafuer einzeln angefasst hatte. Eine Pruefung des ganzen Projekts zeigte
zwei Luecken:
* in common.sh gab es neun verstreute Aufrufstellen von dialog/whiptail
* migrate_creator.sh hatte noch durchgehend feste Groessen
(20 76 11, 10 76, 18 76, 14 76, 22 78, 8 76)
Beide Skripte rufen dialog/whiptail jetzt nur noch ueber drei Stellen auf:
_ui_list Listenfenster (menu, checklist, radiolist)
_ui_box Textfenster (msgbox, yesno, inputbox, passwordbox, infobox)
_ui_file Dateianzeige (textbox)
Die berechnen die Groesse selbst. Damit stimmt sie auch fuer Fenster, die
spaeter dazukommen - man muss nur eine der ui_*-Huellen benutzen.
Neu: "cmk-manage.sh selftest" haelt das nach. Geprueft werden Syntax
aller vier Skripte, Dialoge an den Engstellen vorbei, fest eingetragene
Fenstergroessen, das Muster "[ ... ] && VAR=..." und die Vollstaendigkeit
der Einstellungstabelle gegenueber .env.example.
Der Lauf fand sofort 19 Altlasten des Musters "[ ... ] && VAR=...", das
hier schon dreimal einen stillen Abbruch verursacht hat - alle in
if-Bloecke umgeschrieben und stichprobenartig geprueft, auch die Faelle
mit case-Abschluss und Array-Zuweisung. Danach laeuft die Selbstpruefung
vollstaendig durch.
Regression: alle CLI-Kommandos, zwoelf Menuefunktionen und das Rendern
von sechs Fenstern unter whiptail in einem echten Pseudo-Terminal.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -107,13 +107,96 @@ ui_init() {
|
||||
else UI_BIN=""; fi
|
||||
UI_BACKTITLE="migrate_creator $VERSION - $(hostname)"
|
||||
}
|
||||
ui_menu() { local t="$1" x="$2"; shift 2; "$UI_BIN" --backtitle "$UI_BACKTITLE" --title "$t" --menu "$x" 20 76 11 "$@" 3>&1 1>&2 2>&3; }
|
||||
ui_checklist() { local t="$1" x="$2"; shift 2; "$UI_BIN" --backtitle "$UI_BACKTITLE" --title "$t" --checklist "$x" 20 76 11 "$@" 3>&1 1>&2 2>&3; }
|
||||
ui_input() { "$UI_BIN" --backtitle "$UI_BACKTITLE" --title "$1" --inputbox "$2" 10 76 "${3:-}" 3>&1 1>&2 2>&3; }
|
||||
ui_msg() { "$UI_BIN" --backtitle "$UI_BACKTITLE" --title "$1" --msgbox "$2" 18 76; }
|
||||
ui_yesno() { "$UI_BIN" --backtitle "$UI_BACKTITLE" --title "$1" --yesno "$2" 14 76; }
|
||||
ui_text() { "$UI_BIN" --backtitle "$UI_BACKTITLE" --title "$1" --textbox "$2" 22 78; }
|
||||
ui_info() { "$UI_BIN" --backtitle "$UI_BACKTITLE" --title "$1" --infobox "$2" 8 76; }
|
||||
# --- Fenstergroesse berechnen ----------------------------------------
|
||||
# Wie im Hauptskript: die Groesse ergibt sich aus Terminal, Textlaenge
|
||||
# und Anzahl der Eintraege. Feste Werte fuehrten bei langem Text dazu,
|
||||
# dass von der Auswahlliste nur noch eine Zeile sichtbar war.
|
||||
# Hier bewusst mit if-Bloecken statt "[ ... ] && VAR=..." - letzteres
|
||||
# liefert 1, wenn die Bedingung nicht zutrifft, und beendet unter
|
||||
# "set -e" die Funktion.
|
||||
ui_term_size() {
|
||||
UI_ROWS="$(tput lines 2>/dev/null || true)"
|
||||
UI_COLS="$(tput cols 2>/dev/null || true)"
|
||||
case "$UI_ROWS" in ''|*[!0-9]*) UI_ROWS=24 ;; esac
|
||||
case "$UI_COLS" in ''|*[!0-9]*) UI_COLS=80 ;; esac
|
||||
if [ "$UI_ROWS" -lt 10 ]; then UI_ROWS=24; fi
|
||||
if [ "$UI_COLS" -lt 40 ]; then UI_COLS=80; fi
|
||||
return 0
|
||||
}
|
||||
|
||||
ui_calc() { # text felder_je_eintrag eintraege...
|
||||
local text="$1" per="$2"; shift 2
|
||||
ui_term_size
|
||||
local tl maxw
|
||||
tl="$(printf '%s\n' "$text" | wc -l)"
|
||||
maxw="$(printf '%s\n' "$text" | awk '{ if (length($0) > m) m = length($0) } END { print m+0 }')"
|
||||
local -a args=("$@")
|
||||
local i=0 w itemw=0 n=0
|
||||
while [ "$i" -lt "${#args[@]}" ]; do
|
||||
w=$(( ${#args[$i]} + 4 ))
|
||||
if [ $((i+1)) -lt "${#args[@]}" ]; then w=$(( w + ${#args[$((i+1))]} )); fi
|
||||
if [ "$w" -gt "$itemw" ]; then itemw="$w"; fi
|
||||
i=$(( i + per )); n=$(( n + 1 ))
|
||||
done
|
||||
if [ "$maxw" -gt "$itemw" ]; then UI_W=$(( maxw + 10 )); else UI_W=$(( itemw + 10 )); fi
|
||||
if [ "$UI_W" -lt 60 ]; then UI_W=60; fi
|
||||
if [ "$UI_W" -gt $(( UI_COLS - 4 )) ]; then UI_W=$(( UI_COLS - 4 )); fi
|
||||
local avail=$(( UI_ROWS - tl - 9 ))
|
||||
if [ "$avail" -lt 3 ]; then avail=3; fi
|
||||
if [ "$n" -lt "$avail" ]; then UI_MH="$n"; else UI_MH="$avail"; fi
|
||||
if [ "$UI_MH" -lt 1 ]; then UI_MH=1; fi
|
||||
UI_H=$(( tl + UI_MH + 8 ))
|
||||
if [ "$UI_H" -gt $(( UI_ROWS - 2 )) ]; then UI_H=$(( UI_ROWS - 2 )); fi
|
||||
if [ "$UI_H" -lt 10 ]; then UI_H=10; fi
|
||||
return 0
|
||||
}
|
||||
|
||||
ui_calc_text() { # text zusatzzeilen
|
||||
local text="$1" extra="${2:-7}"
|
||||
ui_term_size
|
||||
local tl maxw
|
||||
tl="$(printf '%s\n' "$text" | wc -l)"
|
||||
maxw="$(printf '%s\n' "$text" | awk '{ if (length($0) > m) m = length($0) } END { print m+0 }')"
|
||||
UI_W=$(( maxw + 10 ))
|
||||
if [ "$UI_W" -lt 60 ]; then UI_W=60; fi
|
||||
if [ "$UI_W" -gt $(( UI_COLS - 4 )) ]; then UI_W=$(( UI_COLS - 4 )); fi
|
||||
UI_H=$(( tl + extra ))
|
||||
if [ "$UI_H" -gt $(( UI_ROWS - 2 )) ]; then UI_H=$(( UI_ROWS - 2 )); fi
|
||||
if [ "$UI_H" -lt 8 ]; then UI_H=8; fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# --- Engstellen: hierueber laufen ALLE Dialoge ------------------------
|
||||
_ui_list() { # widget titel text felder_je_eintrag eintraege...
|
||||
local widget="$1" t="$2" x="$3" per="$4"; shift 4
|
||||
ui_calc "$x" "$per" "$@"
|
||||
"$UI_BIN" --backtitle "$UI_BACKTITLE" --title "$t" \
|
||||
"$widget" "$x" "$UI_H" "$UI_W" "$UI_MH" "$@" 3>&1 1>&2 2>&3
|
||||
}
|
||||
_ui_box() { # widget titel text zusatzzeilen [weitere]
|
||||
local widget="$1" t="$2" x="$3" extra="$4"; shift 4
|
||||
ui_calc_text "$x" "$extra"
|
||||
case "$widget" in
|
||||
--inputbox|--passwordbox)
|
||||
"$UI_BIN" --backtitle "$UI_BACKTITLE" --title "$t" \
|
||||
"$widget" "$x" "$UI_H" "$UI_W" "$@" 3>&1 1>&2 2>&3 ;;
|
||||
*) "$UI_BIN" --backtitle "$UI_BACKTITLE" --title "$t" \
|
||||
"$widget" "$x" "$UI_H" "$UI_W" "$@" ;;
|
||||
esac
|
||||
}
|
||||
_ui_file() { # titel datei
|
||||
ui_term_size
|
||||
"$UI_BIN" --backtitle "$UI_BACKTITLE" --title "$1" --textbox "$2" \
|
||||
$(( UI_ROWS - 2 )) $(( UI_COLS - 4 ))
|
||||
}
|
||||
|
||||
ui_menu() { local t="$1" x="$2"; shift 2; _ui_list --menu "$t" "$x" 2 "$@"; }
|
||||
ui_checklist() { local t="$1" x="$2"; shift 2; _ui_list --checklist "$t" "$x" 3 "$@"; }
|
||||
ui_input() { _ui_box --inputbox "$1" "$2" 10 "${3:-}"; }
|
||||
ui_msg() { _ui_box --msgbox "$1" "$2" 7; }
|
||||
ui_yesno() { _ui_box --yesno "$1" "$2" 8; }
|
||||
ui_info() { _ui_box --infobox "$1" "$2" 5; }
|
||||
ui_text() { _ui_file "$1" "$2"; }
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# Bundle erzeugen
|
||||
|
||||
Reference in New Issue
Block a user