From 176ba3ba6ea7e14c6d4c7b7322005fbea293bebf Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Sun, 6 Oct 2024 20:41:03 +0200 Subject: [PATCH] Extend show_infobox to skip dialog if terminal is not defined --- lib/armbian-configng/config.ng.functions.sh | 47 ++++++++++++--------- tests/S01.conf | 3 ++ 2 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 tests/S01.conf diff --git a/lib/armbian-configng/config.ng.functions.sh b/lib/armbian-configng/config.ng.functions.sh index 14d754e2b..3b6404139 100644 --- a/lib/armbian-configng/config.ng.functions.sh +++ b/lib/armbian-configng/config.ng.functions.sh @@ -678,28 +678,35 @@ module_options+=( # Function to display an infobox with a message # function show_infobox() { - export TERM=ansi - local input - local BACKTITLE="$BACKTITLE" - local -a buffer # Declare buffer as an array - if [ -p /dev/stdin ]; then - while IFS= read -r line; do - buffer+=("$line") # Add the line to the buffer - # If the buffer has more than 10 lines, remove the oldest line - if ((${#buffer[@]} > 18)); then - buffer=("${buffer[@]:1}") - fi - # Display the lines in the buffer in the infobox - TERM=ansi $DIALOG --title "$TITLE" --infobox "$(printf "%s\n" "${buffer[@]}")" 16 90 - sleep 0.5 - done - else + local input="$1" + local -a buffer # Declare buffer as an array + if [ -p /dev/stdin ]; then + while IFS= read -r line; do + buffer+=("$line") # Add the line to the buffer + # If the buffer has more than 10 lines, remove the oldest line + if ((${#buffer[@]} > 18)); then + buffer=("${buffer[@]:1}") + fi + if [ -t 0 ]; then + # Display the lines in the buffer in the infobox + $DIALOG --title "$TITLE" --infobox "$(printf "%s\n" "${buffer[@]}")" 16 90 + else + # Terminal not defined - proceed without TUI + printf "%s\n" "${buffer[@]}" + fi + sleep 0.5 + done + else - input="$1" - TERM=ansi $DIALOG --title "$TITLE" --infobox "$input" 6 80 - fi - echo -ne '\033[3J' # clear the screen + if [ -t 0 ]; then + TERM=ansi $DIALOG --title "$TITLE" --infobox "$input" 6 80 + else + # Terminal not defined - proceed without TUI + echo $input + fi + fi + echo -ne '\033[3J' # clear the screen } module_options+=( diff --git a/tests/S01.conf b/tests/S01.conf new file mode 100644 index 000000000..dcdc9f387 --- /dev/null +++ b/tests/S01.conf @@ -0,0 +1,3 @@ +ENABLED=true +PREINSTALL="apt install linux-image-current-x86; apt-mark hold linux-image-current-x86" +CONDITION=""