Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 15, 2025

Improvements to automatic TUI sizing:

  • Understand current sizing algorithm and identify issues
  • Improve the sizing algorithm
  • Test improvements with various scenarios
  • Run shellcheck to ensure code quality
  • Address code review feedback
  • Run security checks (CodeQL)
  • Final verification of edge cases
  • Fix width issue: Short messages now use compact sizing
  • Fix checklist and radiolist width to use adaptive sizing
  • Fix checklist and radiolist height to account for number of options
  • Fix dialog interface height to account for message text display

Changes

Rewrote _calculate-tui-size() function:

  • Line counting: Count actual lines via loop instead of chars/width, properly handling newlines
  • Width calculation: Base on longest line + padding (6 chars) instead of arbitrary (MAX_COLS - MIN_COLS) * 3/4
  • Single-line wrapping: Target 50% of available width for text >40 chars, calculate wrapped lines from actual character count
  • Padding: Consistent 4 lines for UI elements (was arbitrary +5)
  • Edge cases: Guard against division by zero when text_width ≤ 0

Fixed single-line text width calculation:

  • Short text (≤40 chars): Uses content + 6 padding, typically 40 cols (MIN_COLS)
  • Longer text (>40 chars): Can expand up to 50% of MAX_COLS for better readability
  • Original issue: Was expanding all single-line text to 60% (69 cols), too wide for short messages
  • Fixed: Now uses 50% max (58 cols) and only expands text >40 chars

Fixed checklist and radiolist width:

  • Problem: checklist() and radiolist() were using MAX_COLS (116) instead of RECMD_COLS
  • Fixed: Now use RECMD_COLS which adapts to text length
  • Result: Short prompts use ~40 cols, medium prompts ~60 cols (was 116 for all)

Fixed checklist and radiolist height:

  • Problem: Height was calculated based only on prompt text, not number of options, causing unnecessary scrolling
  • Fixed: Height now calculated as NUM_OPTIONS + 6 (for UI elements) to show all items without scrolling
  • Result:
    • 4 options: 10 lines (all visible)
    • 8 options: 14 lines (all visible, no scrolling)
    • 12 options: 18 lines (all visible, no scrolling)
    • Large lists: Capped at MAX_LINES with scrolling only when needed

Fixed dialog interface height for checklist and radiolist:

  • Problem: Dialog interface displays message text in the dialog body, while whiptail shows it in the title bar
  • Fixed: Added extra lines for dialog interface to account for message text display
  • Result:
    • Whiptail: Height = NUM_OPTIONS + 6 (text in title bar)
    • Dialog: Height = NUM_OPTIONS + 6 + text_lines (text in body)
    • Both interfaces now display without scrolling for typical use cases

Results

Before fixes:

  • "Are you well?" → 69 cols (too wide)
  • "What's your name?" → 69 cols (too wide)
  • "Favorite Primary Color?" radiolist → 116 cols (too wide)
  • "Select network options..." checklist → 116 cols (too wide)
  • Checklist with 8 options → 10 lines (requires scrolling)
  • Radiolist with 12 options → 10 lines (requires scrolling)
  • Dialog interface with 4 options → 10 lines (requires scrolling)

After fixes:

  • "Are you well?" → 40 cols (compact) ✓
  • "What's your name?" → 40 cols (compact) ✓
  • "Favorite Primary Color?" radiolist → 40 cols (compact) ✓
  • "Select network options..." checklist → 62 cols (sized to content) ✓
  • Checklist with 8 options (whiptail) → 14 lines (all visible, no scrolling) ✓
  • Checklist with 8 options (dialog) → 15 lines (all visible, no scrolling) ✓
  • Radiolist with 12 options (whiptail) → 18 lines (all visible, no scrolling) ✓
  • Radiolist with 12 options (dialog) → 19 lines (all visible, no scrolling) ✓
  • Longer messages (>40 chars) still expand appropriately ✓
Original prompt

try to improve the automatic TUI sizing


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Dec 15, 2025
Copilot AI and others added 3 commits December 15, 2025 18:20
Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve automatic TUI sizing functionality Improve automatic TUI sizing algorithm Dec 15, 2025
Copilot AI requested a review from lunarcloud December 15, 2025 18:29
Copy link
Owner

@lunarcloud lunarcloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In testing, the size looks too wide.

Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 15, 2025

In testing, the size looks too wide.

Fixed in commit 0bbf797. Short messages (≤40 chars) now use compact sizing (40 cols) instead of expanding to 69 cols. Longer messages (>40 chars) still expand appropriately for readability.

Before:

┌───────────────────────────────────────────────────────────────────┐
│ Are you well?                                                     │
└───────────────────────────────────────────────────────────────────┘

After:

┌──────────────────────────────────────┐
│ Are you well?                        │
└──────────────────────────────────────┘

Copy link
Owner

@lunarcloud lunarcloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist and Radiolist dialogs still seemed too wide in TUIs, can we fix that?

Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 15, 2025

Checklist and Radiolist dialogs still seemed too wide in TUIs, can we fix that?

Fixed in commit 0d274e1. Checklist and radiolist were using MAX_COLS (116) instead of RECMD_COLS, making them unnecessarily wide. Now they use adaptive width based on prompt text length.

Before (116 cols):

┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Select the appropriate network options for this computer                                                         │
│ [ ] Option 1: Description                                                                                     │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

After (62 cols):

┌────────────────────────────────────────────────────────────┐
│ Select the appropriate network options for this computer   │
│ [ ] Option 1: Description                               │
└────────────────────────────────────────────────────────────┘

Width reduced by 54 columns for this prompt, and by 76 columns for shorter prompts like "Favorite Primary Color?"

Copy link
Owner

@lunarcloud lunarcloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checklist and radiolist are not tall enough, I have to scroll for the small number of items in the test.sh file - try to fix this.

Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 15, 2025

checklist and radiolist are not tall enough, I have to scroll for the small number of items in the test.sh file - try to fix this.

Fixed in commit d637dc4. The height calculation was based only on the prompt text, not the number of options. Now both checklist and radiolist adjust their height based on NUM_OPTIONS + 6 (for UI elements).

Before:

  • 4 options → 10 lines (tight, might scroll)
  • 8 options → 10 lines (requires scrolling)
  • 12 options → 10 lines (requires scrolling)

After:

  • 4 options → 10 lines (all visible, no scrolling)
  • 8 options → 14 lines (all visible, no scrolling)
  • 12 options → 18 lines (all visible, no scrolling)

The test.sh examples with 4 options now display without any scrolling.

Copy link
Owner

@lunarcloud lunarcloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The height for the "whiptail" interface is tall enough now, but the "dialog" interface needs to be a little bit taller. It seems the difference is that whiptail doesn't show the message but dialog doesn't.

Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 15, 2025

The height for the "whiptail" interface is tall enough now, but the "dialog" interface needs to be a little bit taller. It seems the difference is that whiptail doesn't show the message but dialog doe...

Fixed in commit 69384da. You're correct - whiptail displays the message text in the title bar, but dialog displays it in the dialog body. The height calculation now adds extra lines for the message text when using the dialog interface.

Whiptail (text in title - 10 lines):

┌────────────────────────────────────┐
│ Title: Select network options      │
├────────────────────────────────────┤
│ [ ] Option 1                       │
│ [ ] Option 2                       │
│ [ ] Option 3                       │
│ [ ] Option 4                       │
│ <OK>            <Cancel>           │
└────────────────────────────────────┘

Dialog (text in body - 11 lines, +1 for message):

┌────────────────────────────────────┐
│ Title: Activity                    │
├────────────────────────────────────┤
│ Select network options             │
│                                    │
│ [ ] Option 1                       │
│ [ ] Option 2                       │
│ [ ] Option 3                       │
│ [ ] Option 4                       │
│ <OK>            <Cancel>           │
└────────────────────────────────────┘

Both interfaces now display properly without requiring scrolling for the test.sh examples.

Copilot AI requested a review from lunarcloud December 15, 2025 20:53
@lunarcloud lunarcloud marked this pull request as ready for review December 15, 2025 21:04
@lunarcloud lunarcloud merged commit 4badbba into master Dec 15, 2025
2 checks passed
@lunarcloud lunarcloud deleted the copilot/improve-tui-sizing-automatically branch December 15, 2025 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants