emrg: clear terminal residue on width shrink (rant 2026-08-14T11:47:11) - #781
Conversation
argszero
left a comment
There was a problem hiding this comment.
✅ 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
left a comment
There was a problem hiding this comment.
✅ LGTM — cycle
Reviewed the full diff on checkout:
- Root cause verified:
Buffer.resizeshrink physically truncates old-width cells,diff_buffersonly diffsmin(prev_w, curr_w)columns, andhandle_resizehad 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_SCREENconfirmed defined in output.py:29;_last_render_widthinitialized 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
left a comment
There was a problem hiding this comment.
✅ 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
left a comment
There was a problem hiding this comment.
✅ 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)
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:
Buffer.resize(w, h)shrink truncates the cell arrays — old-width info is physically lost.diff_buffersonly comparesmin(prev.width, curr.width)columns — columns outside the new width are never diffed.handle_resizeonly 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:self._last_render_width(initialized to caps.width).width < _last_render_width: writeCLEAR_SCREEN(\x1b[2J, scrollback preserved), clear the front buffer, and forcefull=True— the diff engine then redraws everything cleanly.Tests — new
tests/test_terminal_render.py(3 cases, POSIX-only like test_app_widgets):pytest: 801 → 804 green (Agent.md count synced). Import + CLI checks pass.