Przeglądaj źródła

fix(core): fall back to 80 columns when no terminal width is available (#4974)

Separators and centred text used the width from tput cols. Without a
terminal (cron, Docker, post-details), tput prints an error and returns
nothing. bash 5.3 (Ubuntu 26.04) also rejects the empty printf width
("printf: : invalid number"). Hide tput's error and fall back to 80
columns. Terminal widths are still used when available.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Daniel Gibbs 1 tydzień temu
rodzic
commit
6edc5b68bf
2 zmienionych plików z 9 dodań i 3 usunięć
  1. 3 1
      lgsm/modules/core_messages.sh
  2. 6 2
      linuxgsm.sh

+ 3 - 1
lgsm/modules/core_messages.sh

@@ -222,7 +222,9 @@ fn_print_start_nl() {
 # Separator is different for details.
 # Separator is different for details.
 fn_messages_separator() {
 fn_messages_separator() {
 	if [ "${commandname}" == "DETAILS" ]; then
 	if [ "${commandname}" == "DETAILS" ]; then
-		printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
+		# Fall back to 80 columns when there is no terminal (e.g. cron or Docker); bash 5.3+ rejects an empty printf width.
+		local columns="${COLUMNS:-$(tput cols 2> /dev/null)}"
+		printf '%*s\n' "${columns:-80}" '' | tr ' ' =
 	else
 	else
 		echo -e "${bold}=================================${default}"
 		echo -e "${bold}=================================${default}"
 		fn_sleep_time
 		fn_sleep_time

+ 6 - 2
linuxgsm.sh

@@ -243,13 +243,17 @@ fn_bootstrap_fetch_file_github() {
 # Installer menu.
 # Installer menu.
 
 
 fn_print_center() {
 fn_print_center() {
-	columns=$(tput cols)
+	# Fall back to 80 columns when there is no terminal.
+	columns="${COLUMNS:-$(tput cols 2> /dev/null)}"
+	columns="${columns:-80}"
 	line="$*"
 	line="$*"
 	printf "%*s\n" $(((${#line} + columns) / 2)) "${line}"
 	printf "%*s\n" $(((${#line} + columns) / 2)) "${line}"
 }
 }
 
 
 fn_print_horizontal() {
 fn_print_horizontal() {
-	printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' "="
+	# Fall back to 80 columns when there is no terminal; bash 5.3+ rejects an empty printf width.
+	local columns="${COLUMNS:-$(tput cols 2> /dev/null)}"
+	printf '%*s\n' "${columns:-80}" '' | tr ' ' "="
 }
 }
 
 
 # Bash menu.
 # Bash menu.