From 736e354c840633ec5a8b177eb503dfb06b3d546f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 18:13:42 +0000 Subject: [PATCH 1/8] Initial plan From 90ba2d989da5eb0c5f2d289642c98e15fc215a9b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 18:20:36 +0000 Subject: [PATCH 2/8] Improve automatic TUI sizing algorithm Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com> --- script-dialog.sh | 63 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/script-dialog.sh b/script-dialog.sh index 20a2deb..99aaf64 100755 --- a/script-dialog.sh +++ b/script-dialog.sh @@ -325,31 +325,76 @@ function _calculate-tui-max() { ####################################### function _calculate-tui-size() { _calculate-tui-max - local CHARS=${#TEST_STRING} RECMD_SCROLL=false - RECMD_COLS=$((( MAX_COLS - MIN_COLS ) * 3 / 4)) - RECMD_LINES=$(((CHARS / RECMD_COLS) + 5)) - if [[ "$RECMD_LINES" -lt 7 ]]; then + + # Handle empty string case + if [ -z "$TEST_STRING" ]; then RECMD_COLS=$MIN_COLS - RECMD_LINES=$(((CHARS / RECMD_COLS) + 5)) + RECMD_LINES=$MIN_LINES + TEST_STRING="" + return fi - + + # Count actual lines and find longest line + local line_count=0 + local max_line_length=0 + + while IFS= read -r line; do + line_count=$((line_count + 1)) + local line_len=${#line} + if [ "$line_len" -gt "$max_line_length" ]; then + max_line_length=$line_len + fi + done <<< "$TEST_STRING" + + # Calculate recommended columns based on longest line + # Add padding for borders, margins, and UI elements (typically 4-6 chars) + RECMD_COLS=$((max_line_length + 6)) + + # For single-line text, consider wrapping and use a reasonable width + if [ "$line_count" -eq 1 ]; then + local total_chars=${#TEST_STRING} + + # Target width: 60% of available space, but at least MIN_COLS + local target_width=$((MAX_COLS * 3 / 5)) + if [ "$target_width" -lt "$MIN_COLS" ]; then + target_width=$MIN_COLS + fi + + # Use the larger of: calculated width or target width + if [ "$RECMD_COLS" -lt "$target_width" ]; then + RECMD_COLS=$target_width + fi + + # Calculate wrapped line count at this width + # Subtract padding to get actual text width + local text_width=$((RECMD_COLS - 6)) + if [ "$text_width" -lt 1 ]; then + text_width=1 + fi + line_count=$(((total_chars + text_width - 1) / text_width)) + fi + + # Calculate recommended lines with padding for UI elements + # Add 4 lines for title, borders, and buttons + RECMD_LINES=$((line_count + 4)) + + # Enforce maximum constraints if [ "$RECMD_LINES" -gt "$MAX_LINES" ] ; then RECMD_LINES=$MAX_LINES RECMD_SCROLL=true fi if [ "$RECMD_COLS" -gt "$MAX_COLS" ]; then RECMD_COLS=$MAX_COLS - #RECMD_SCROLL=true + RECMD_SCROLL=true fi + # Enforce minimum constraints if [ "$RECMD_LINES" -lt "$MIN_LINES" ] ; then RECMD_LINES=$MIN_LINES - RECMD_SCROLL=false fi if [ "$RECMD_COLS" -lt "$MIN_COLS" ]; then RECMD_COLS=$MIN_COLS - RECMD_SCROLL=false fi TEST_STRING="" #blank out for memory's sake From 636ee58a99c792cc68d8a567ab8402f0ea3943f7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 18:23:14 +0000 Subject: [PATCH 3/8] Address code review feedback Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com> --- script-dialog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script-dialog.sh b/script-dialog.sh index 99aaf64..26990d0 100755 --- a/script-dialog.sh +++ b/script-dialog.sh @@ -331,7 +331,6 @@ function _calculate-tui-size() { if [ -z "$TEST_STRING" ]; then RECMD_COLS=$MIN_COLS RECMD_LINES=$MIN_LINES - TEST_STRING="" return fi @@ -372,6 +371,7 @@ function _calculate-tui-size() { if [ "$text_width" -lt 1 ]; then text_width=1 fi + # Calculate ceiling division: (total_chars + text_width - 1) / text_width line_count=$(((total_chars + text_width - 1) / text_width)) fi From b8bd942e8eeed86ad3ddd644e4406aba74e02edb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 18:26:32 +0000 Subject: [PATCH 4/8] Fix potential edge case in text width calculation Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com> --- script-dialog.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script-dialog.sh b/script-dialog.sh index 26990d0..6e30f24 100755 --- a/script-dialog.sh +++ b/script-dialog.sh @@ -368,7 +368,8 @@ function _calculate-tui-size() { # Calculate wrapped line count at this width # Subtract padding to get actual text width local text_width=$((RECMD_COLS - 6)) - if [ "$text_width" -lt 1 ]; then + # Ensure text_width is at least 1 to avoid division by zero + if [ "$text_width" -le 0 ]; then text_width=1 fi # Calculate ceiling division: (total_chars + text_width - 1) / text_width From 0bbf79780f0d9aa9713e30c38a7684853ad5e2fc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 19:11:28 +0000 Subject: [PATCH 5/8] Reduce dialog width for short messages Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com> --- script-dialog.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/script-dialog.sh b/script-dialog.sh index 6e30f24..74eadf6 100755 --- a/script-dialog.sh +++ b/script-dialog.sh @@ -354,14 +354,16 @@ function _calculate-tui-size() { if [ "$line_count" -eq 1 ]; then local total_chars=${#TEST_STRING} - # Target width: 60% of available space, but at least MIN_COLS - local target_width=$((MAX_COLS * 3 / 5)) + # Target width: Start with content + padding, but cap at a reasonable maximum + # Use 50% of available space as the maximum for single-line text + local target_width=$((MAX_COLS / 2)) if [ "$target_width" -lt "$MIN_COLS" ]; then target_width=$MIN_COLS fi - # Use the larger of: calculated width or target width - if [ "$RECMD_COLS" -lt "$target_width" ]; then + # Only expand to target width if text is long enough to benefit from it + # For short text, stay closer to content size + if [ "$RECMD_COLS" -lt "$target_width" ] && [ "$total_chars" -gt 40 ]; then RECMD_COLS=$target_width fi From 0d274e1b900c48c75e2bd25c3665e09c6c3093bf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 19:23:30 +0000 Subject: [PATCH 6/8] Fix checklist and radiolist to use adaptive width Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com> --- script-dialog.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/script-dialog.sh b/script-dialog.sh index 74eadf6..c50dde0 100755 --- a/script-dialog.sh +++ b/script-dialog.sh @@ -931,9 +931,9 @@ function checklist() { _calculate-tui-size if [ "$INTERFACE" == "whiptail" ]; then - mapfile -t CHOSEN_ITEMS < <( whiptail --clear --backtitle "$APP_NAME" --title "$ACTIVITY" $([ "$RECMD_SCROLL" == true ] && echo "--scrolltext") --checklist "${QUESTION_SYMBOL}$TEXT" $RECMD_LINES $MAX_COLS "$NUM_OPTIONS" "$@" 3>&1 1>&2 2>&3) + mapfile -t CHOSEN_ITEMS < <( whiptail --clear --backtitle "$APP_NAME" --title "$ACTIVITY" $([ "$RECMD_SCROLL" == true ] && echo "--scrolltext") --checklist "${QUESTION_SYMBOL}$TEXT" $RECMD_LINES $RECMD_COLS "$NUM_OPTIONS" "$@" 3>&1 1>&2 2>&3) elif [ "$INTERFACE" == "dialog" ]; then - IFS=$'\n' read -r -d '' -a CHOSEN_LIST < <( dialog --clear --backtitle "$APP_NAME" --title "$ACTIVITY" $([ "$RECMD_SCROLL" == true ] && echo "--scrolltext") --separate-output --checklist "${QUESTION_SYMBOL}$TEXT" $RECMD_LINES $MAX_COLS "$NUM_OPTIONS" "$@" 3>&1 1>&2 2>&3) + IFS=$'\n' read -r -d '' -a CHOSEN_LIST < <( dialog --clear --backtitle "$APP_NAME" --title "$ACTIVITY" $([ "$RECMD_SCROLL" == true ] && echo "--scrolltext") --separate-output --checklist "${QUESTION_SYMBOL}$TEXT" $RECMD_LINES $RECMD_COLS "$NUM_OPTIONS" "$@" 3>&1 1>&2 2>&3) local CHOSEN_ITEMS=() for value in "${CHOSEN_LIST[@]}" @@ -1024,9 +1024,9 @@ function radiolist() { _calculate-tui-size if [ "$INTERFACE" == "whiptail" ]; then - CHOSEN_ITEM=$( whiptail --clear --backtitle "$APP_NAME" --title "$ACTIVITY" $([ "$RECMD_SCROLL" == true ] && echo "--scrolltext") --radiolist "${QUESTION_SYMBOL}$TEXT" $RECMD_LINES $MAX_COLS "$NUM_OPTIONS" "$@" 3>&1 1>&2 2>&3) + CHOSEN_ITEM=$( whiptail --clear --backtitle "$APP_NAME" --title "$ACTIVITY" $([ "$RECMD_SCROLL" == true ] && echo "--scrolltext") --radiolist "${QUESTION_SYMBOL}$TEXT" $RECMD_LINES $RECMD_COLS "$NUM_OPTIONS" "$@" 3>&1 1>&2 2>&3) elif [ "$INTERFACE" == "dialog" ]; then - CHOSEN_ITEM=$( dialog --clear --backtitle "$APP_NAME" --title "$ACTIVITY" $([ "$RECMD_SCROLL" == true ] && echo "--scrolltext") --quoted --radiolist "${QUESTION_SYMBOL}$TEXT" $RECMD_LINES $MAX_COLS "$NUM_OPTIONS" "$@" 3>&1 1>&2 2>&3) + CHOSEN_ITEM=$( dialog --clear --backtitle "$APP_NAME" --title "$ACTIVITY" $([ "$RECMD_SCROLL" == true ] && echo "--scrolltext") --quoted --radiolist "${QUESTION_SYMBOL}$TEXT" $RECMD_LINES $RECMD_COLS "$NUM_OPTIONS" "$@" 3>&1 1>&2 2>&3) elif [ "$INTERFACE" == "zenity" ]; then OPTIONS=() while test ${#} -gt 0; do From d637dc4c3dcefa3b19c161bcf96165262dbf4320 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 20:39:24 +0000 Subject: [PATCH 7/8] Fix checklist and radiolist height to account for number of options Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com> --- script-dialog.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/script-dialog.sh b/script-dialog.sh index c50dde0..3de4ebd 100755 --- a/script-dialog.sh +++ b/script-dialog.sh @@ -929,6 +929,18 @@ function checklist() { shift shift _calculate-tui-size + + # Adjust height to account for the number of options + # Each option takes 1 line, plus we need space for prompt and UI elements + local needed_lines=$((NUM_OPTIONS + 6)) # 6 lines for prompt, borders, and buttons + if [ "$needed_lines" -gt "$RECMD_LINES" ]; then + RECMD_LINES=$needed_lines + # Enforce maximum constraint + if [ "$RECMD_LINES" -gt "$MAX_LINES" ]; then + RECMD_LINES=$MAX_LINES + RECMD_SCROLL=true + fi + fi if [ "$INTERFACE" == "whiptail" ]; then mapfile -t CHOSEN_ITEMS < <( whiptail --clear --backtitle "$APP_NAME" --title "$ACTIVITY" $([ "$RECMD_SCROLL" == true ] && echo "--scrolltext") --checklist "${QUESTION_SYMBOL}$TEXT" $RECMD_LINES $RECMD_COLS "$NUM_OPTIONS" "$@" 3>&1 1>&2 2>&3) @@ -1022,6 +1034,18 @@ function radiolist() { shift shift _calculate-tui-size + + # Adjust height to account for the number of options + # Each option takes 1 line, plus we need space for prompt and UI elements + local needed_lines=$((NUM_OPTIONS + 6)) # 6 lines for prompt, borders, and buttons + if [ "$needed_lines" -gt "$RECMD_LINES" ]; then + RECMD_LINES=$needed_lines + # Enforce maximum constraint + if [ "$RECMD_LINES" -gt "$MAX_LINES" ]; then + RECMD_LINES=$MAX_LINES + RECMD_SCROLL=true + fi + fi if [ "$INTERFACE" == "whiptail" ]; then CHOSEN_ITEM=$( whiptail --clear --backtitle "$APP_NAME" --title "$ACTIVITY" $([ "$RECMD_SCROLL" == true ] && echo "--scrolltext") --radiolist "${QUESTION_SYMBOL}$TEXT" $RECMD_LINES $RECMD_COLS "$NUM_OPTIONS" "$@" 3>&1 1>&2 2>&3) From 69384da68ed676405925548ee98d34e4eb5bb5a3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 20:50:37 +0000 Subject: [PATCH 8/8] Add extra height for dialog interface to show message text Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com> --- script-dialog.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/script-dialog.sh b/script-dialog.sh index 3de4ebd..cf2636b 100755 --- a/script-dialog.sh +++ b/script-dialog.sh @@ -933,6 +933,17 @@ function checklist() { # Adjust height to account for the number of options # Each option takes 1 line, plus we need space for prompt and UI elements local needed_lines=$((NUM_OPTIONS + 6)) # 6 lines for prompt, borders, and buttons + + # Dialog interface displays the text in the body, whiptail shows it in the title + # Add extra lines for dialog to show the message text + if [ "$INTERFACE" == "dialog" ]; then + local text_lines=0 + while IFS= read -r line; do + text_lines=$((text_lines + 1)) + done <<< "$TEXT" + needed_lines=$((needed_lines + text_lines)) + fi + if [ "$needed_lines" -gt "$RECMD_LINES" ]; then RECMD_LINES=$needed_lines # Enforce maximum constraint @@ -1038,6 +1049,17 @@ function radiolist() { # Adjust height to account for the number of options # Each option takes 1 line, plus we need space for prompt and UI elements local needed_lines=$((NUM_OPTIONS + 6)) # 6 lines for prompt, borders, and buttons + + # Dialog interface displays the text in the body, whiptail shows it in the title + # Add extra lines for dialog to show the message text + if [ "$INTERFACE" == "dialog" ]; then + local text_lines=0 + while IFS= read -r line; do + text_lines=$((text_lines + 1)) + done <<< "$TEXT" + needed_lines=$((needed_lines + text_lines)) + fi + if [ "$needed_lines" -gt "$RECMD_LINES" ]; then RECMD_LINES=$needed_lines # Enforce maximum constraint