Skip to content

Size inline widget panel to rendered (not source) line count#273

Merged
edwin-zvs merged 1 commit into
mainfrom
tui-widget-content-aware-height
May 30, 2026
Merged

Size inline widget panel to rendered (not source) line count#273
edwin-zvs merged 1 commit into
mainfrom
tui-widget-content-aware-height

Conversation

@edwin-zvs

Copy link
Copy Markdown
Contributor

Problem

The TUI's inline widget panel was nominally content-aware (inline_widget_rows counted non-empty source markdown lines and added 2 for borders) but used the wrong metric: source line count, not rendered line count. Any line long enough to wrap at the panel's content width counted as 1 source line but rendered to multiple terminal rows, so wide widgets got a too-short panel and the content was clipped.

Meanwhile the webui's .session-widgets.inline-open { max-height: min(45vh, 280px); } plus default height: auto makes the browser auto-size to actual rendered content up to the cap — which is the behavior you'd expect.

Fix

Measure the actual rendered Vec<Line> (render_agentd_markdown_lines with a throwaway hits buffer + dummy position) and feed it through the existing visual_line_count at the real content width. The real render later does the same parse against the real panel area and registers hits then.

  • One extra markdown parse per frame per inline widget. Widget markdown is short, so the cost is negligible.
  • No protocol/webui changes — the webui already does the right thing.

Test

crates/cli/src/ui.rs — three unit tests:

  • inline_widget_rows_floors_at_three — empty markdown still gets the minimum row budget.
  • inline_widget_rows_accounts_for_wrapping_long_lines — a 200-char single line needs more rows at width 40 than at width 220. This is the regression the old source-count missed.
  • inline_widget_rows_caps_at_available_height — a 500-line widget never exceeds available_height.
cargo test -p agentd-cli   # 197 + 1 passed, 0 failed

🤖 Generated with Claude Code

`inline_widget_rows` counted source markdown lines, which under-counts
any line long enough to wrap at the panel's content width. The result:
wide widgets rendered into a too-short panel and the content got
clipped — the webui's CSS auto-sizing does the right thing, but the TUI
did not.

Measure the actual rendered Line vec (`render_agentd_markdown_lines`
with a throwaway hits buffer) and feed it through `visual_line_count` at
the real content width. The real render later does the same parse
against the real panel area and registers hits then. One extra markdown
parse per frame per widget — widget markdown is short, so the cost is
negligible.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@edwin-zvs
edwin-zvs merged commit e9b7383 into main May 30, 2026
1 check passed
@edwin-zvs
edwin-zvs deleted the tui-widget-content-aware-height branch May 30, 2026 18:31
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.

1 participant