Skip to content

emrg: clear terminal residue on width shrink (rant 2026-08-14T11:47:11) - #781

Merged
argszero merged 1 commit into
masterfrom
feature/tui-width-shrink-residue-fix
Aug 14, 2026
Merged

emrg: clear terminal residue on width shrink (rant 2026-08-14T11:47:11)#781
argszero merged 1 commit into
masterfrom
feature/tui-width-shrink-residue-fix

Conversation

@argszero

Copy link
Copy Markdown
Owner

Fix TUI layout corruption when the terminal window is narrowed (host rant 2026-08-14T11:47:11).

Root cause (verified, not guessed)
When the terminal width shrinks, old characters on the right side of each line (beyond the new width) stay on screen and the diff engine cannot clear them:

  1. Buffer.resize(w, h) shrink truncates the cell arrays — old-width info is physically lost.
  2. diff_buffers only compares min(prev.width, curr.width) columns — columns outside the new width are never diffed.
  3. handle_resize only triggers orphan CLEAR_TO_EOL on top/height changes, not on width changes — stale right-side chars remain, overlapping the new layout (e.g. ○ EMRG 0.2.34fo| semrg-de7,@oargszerodeMac-mini.local).

Fix
Terminal.render() detects width narrowing and forces a clean full redraw:

  • Track self._last_render_width (initialized to caps.width).
  • When width < _last_render_width: write CLEAR_SCREEN (\x1b[2J, scrollback preserved), clear the front buffer, and force full=True — the diff engine then redraws everything cleanly.
  • Same-width / grow renders keep the normal incremental diff path (no flicker; grown columns are covered by the diff of min-width).

Tests — new tests/test_terminal_render.py (3 cases, POSIX-only like test_app_widgets):

  • shrink 40→20 emits CLEAR_SCREEN
  • same width renders emit no CLEAR_SCREEN
  • grow 40→60 emits no CLEAR_SCREEN

pytest: 801 → 804 green (Agent.md count synced). Import + CLI checks pass.

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

✅ LGTM — cycle (verified locally: pytest 804 green, import + CLI checks pass; CI test + test-windows both PASS on this PR; diff matches the rant spec: shrink → CLEAR_SCREEN + front-buffer clear + full redraw, same-width/grow untouched; Agent.md count synced 801→804)

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

✅ LGTM — cycle

Reviewed the full diff on checkout:

  • Root cause verified: Buffer.resize shrink physically truncates old-width cells, diff_buffers only diffs min(prev_w, curr_w) columns, and handle_resize had no width-change CLEAR_TO_EOL path — stale right-side chars survive a narrowing, overlapping the new layout. Analysis is accurate.
  • Fix is minimal and targeted: on width < last render width, emit CLEAR_SCREEN (\x1b[2J, scrollback preserved), clear the front buffer, force full redraw; same-width/grow keep the incremental diff path (no flicker).
  • CLEAR_SCREEN confirmed defined in output.py:29; _last_render_width initialized to caps.width.
  • New tests (3, POSIX-only like test_app_widgets) verify positive state (shrink emits CLEAR_SCREEN) + negative states (same-width and grow emit none) — discriminating, not just smoke.
  • Local: 804 pytest passed (801 + 3 new), import + CLI OK. CI test + test-windows both PASS. MERGEABLE.

Needs 2 more ✅ from different cycles.

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

✅ LGTM — cycle (3rd)

Re-verified this cycle: head aabda9f3 unchanged since my R1652 review (single commit, diff identical: terminal.py shrink→CLEAR_SCREEN + front-buffer clear + full redraw, 3 POSIX tests, Agent.md 801→804). Local pytest 804 green; CI test + test-windows PASS; MERGEABLE. 3 consecutive ✅ from 3 cycles (04:02:23Z / 04:02:26Z / now), no ❌ between → merging.

@argszero
argszero merged commit 8af06ba into master Aug 14, 2026
2 checks passed
@argszero
argszero deleted the feature/tui-width-shrink-residue-fix branch August 14, 2026 04:13

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

✅ LGTM — cycle (3rd consecutive ✅ from a different cycle: head unchanged aabda9f, CI test + test-windows both PASS on run 31768492234, diff verified against the rant 11:47:11 spec — width shrink → CLEAR_SCREEN + front-buffer clear + full redraw; Agent.md 801→804 synced)

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