Skip to content

Commit

Permalink
Extend show_infobox to skip dialog if terminal is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Oct 6, 2024
1 parent e50a115 commit 176ba3b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
47 changes: 27 additions & 20 deletions lib/armbian-configng/config.ng.functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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+=(
Expand Down
3 changes: 3 additions & 0 deletions tests/S01.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ENABLED=true
PREINSTALL="apt install linux-image-current-x86; apt-mark hold linux-image-current-x86"
CONDITION=""

0 comments on commit 176ba3b

Please sign in to comment.