Skip to content

fix: force clear terminal on fullRender to prevent stale artifacts on…#1612

Merged
Karanjot786 merged 1 commit into
Karanjot786:mainfrom
pradeep0153:fix/1607-renderer-stale-chars-resize
Jun 23, 2026
Merged

fix: force clear terminal on fullRender to prevent stale artifacts on…#1612
Karanjot786 merged 1 commit into
Karanjot786:mainfrom
pradeep0153:fix/1607-renderer-stale-chars-resize

Conversation

@pradeep0153

@pradeep0153 pradeep0153 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Fixes stale ANSI characters lingering outside the new boundaries when a terminal is resized to be smaller. A \x1b[2J\x1b[H sequence is now dispatched synchronously inside fullRender() to ensure a clean slate before differential lines are drawn. Resolves #1607.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved full-screen terminal rendering to ensure cleaner and more reliable display updates.

@pradeep0153 pradeep0153 requested a review from Karanjot786 as a code owner June 19, 2026 04:38
@github-actions github-actions Bot added type:bug +10 pts. Bug fix. area:core @termuijs/core labels Jun 19, 2026
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Renderer.fullRender() in packages/core/src/terminal/Renderer.ts now writes a synchronous ANSI clear-screen (ESC[2J) and cursor-home (ESC[H) sequence to the terminal before calling _screen.invalidate() and _flush().

Changes

Full Render Terminal Clear

Layer / File(s) Summary
ANSI clear-and-home in fullRender()
packages/core/src/terminal/Renderer.ts
Prepends a synchronous ANSI ESC[2J + ESC[H write to fullRender() before the existing _screen.invalidate() and _flush() calls, ensuring the terminal is wiped before a full redraw.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related issues

  • #1607 – Renderer fails to clear stale characters when the terminal window is resized smaller: The explicit ESC[2J + ESC[H clear added to fullRender() directly addresses residual stale characters left when the terminal is resized to a smaller viewport.
  • #1530: The added terminal clearing in fullRender() targets the same rendering corruption described in this issue during resize/redraw operations.

Suggested labels

type:bug, area:core, quality:clean, level:intermediate

Suggested reviewers

  • Karanjot786

Poem

🐇 A flicker, a flash, the screen goes blank,
ESC[2J is all we have to thank.
No stale chars lurk on edges wide,
The cursor homes with nowhere to hide.
Full render gleams — a clean, crisp view! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem and solution, but the PR is missing the required template sections like 'Which package(s)?', 'Type of Change', and the checklist. Fill out the complete PR template including Which package(s)?, Type of Change checkbox, and Checklist items to meet repository requirements.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly indicates the main change (force clearing terminal on fullRender) and references the issue being fixed.
Linked Issues check ✅ Passed The code change (adding synchronous ANSI clear sequence to fullRender) directly addresses the requirement to clear stale characters when terminal is resized smaller.
Out of Scope Changes check ✅ Passed The single-line change adding terminal clear-and-home sequence is directly scoped to resolving the linked issue about stale ANSI characters.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the needs-star PR author has not starred the repo. label Jun 19, 2026
@github-actions

Copy link
Copy Markdown

Hi @pradeep0153 👋

Star this repo before your PR merges.

Why? GSSoC 2026 contributors who star get priority review and points credit. After you star, push any commit (or re-run this check). The needs-star label lifts automatically.

Thanks for your contribution to TermUI.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/src/terminal/Renderer.ts`:
- Line 105: The code in Renderer.ts hardcodes the ANSI escape sequence for
clearing the screen in the writeSync method call. Instead of using a magic
string, import the clearScreen constant that is already defined in the
utils/ansi.js module and use it in place of the hardcoded sequence. Add
clearScreen to the existing import statement from '../utils/ansi.js' (around
line 8), then update the writeSync call to use clearScreen concatenated with the
cursor home sequence '\x1b[H' instead of the combined hardcoded string.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 695eb2cb-e4a8-4e2c-9f05-9a5fd93053a8

📥 Commits

Reviewing files that changed from the base of the PR and between 550e9c6 and 26dbddf.

📒 Files selected for processing (1)
  • packages/core/src/terminal/Renderer.ts

*/
fullRender(): void {
this._screen.invalidate();
this._terminal.writeSync('\x1b[2J\x1b[H');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if clear sequences are used elsewhere, and whether they're inside or outside sync blocks
rg -n -C3 '\\x1b\[2J|\\x1b\[3J' --type=ts

Repository: Karanjot786/TermUI

Length of output: 2115


🏁 Script executed:

# Find ANSI constants file
fd -i ansi packages/core/src --type f | head -20

Repository: Karanjot786/TermUI

Length of output: 131


🏁 Script executed:

# Check if clearScreen and cursorHome constants exist
rg -n 'clearScreen|cursorHome|const.*x1b' packages/core/src/utils/ --type ts | head -30

Repository: Karanjot786/TermUI

Length of output: 1040


🏁 Script executed:

# Read the full fullRender and _flush implementation to understand the sync blocks
sed -n '103,210p' packages/core/src/terminal/Renderer.ts

Repository: Karanjot786/TermUI

Length of output: 4356


🏁 Script executed:

# Check if there's a cursorHome or similar constant defined
rg -n 'cursor|Home|home' packages/core/src/utils/ansi.ts --type ts

Repository: Karanjot786/TermUI

Length of output: 137


🏁 Script executed:

# Check what's imported/exported in ansi.ts around clearScreen
sed -n '1,70p' packages/core/src/utils/ansi.ts

Repository: Karanjot786/TermUI

Length of output: 2415


🏁 Script executed:

# Check current imports in Renderer.ts
sed -n '1,30p' packages/core/src/terminal/Renderer.ts

Repository: Karanjot786/TermUI

Length of output: 1189


🏁 Script executed:

# Verify if clearScreen is already imported anywhere in Renderer.ts
rg -n 'clearScreen|from.*ansi' packages/core/src/terminal/Renderer.ts

Repository: Karanjot786/TermUI

Length of output: 177


🏁 Script executed:

# Check if there's a cursorHome or cursor-to-home constant
rg -n 'cursorHome|cursor.*Home|export const.*H' packages/core/src/utils/ansi.ts

Repository: Karanjot786/TermUI

Length of output: 44


🏁 Script executed:

# Check the full list of cursor-related constants
sed -n '14,50p' packages/core/src/utils/ansi.ts

Repository: Karanjot786/TermUI

Length of output: 1245


Use the clearScreen constant instead of hardcoding the ANSI sequence.

The clearScreen constant is already defined in packages/core/src/utils/ansi.ts as export const clearScreen = ${CSI}2J;. Import and use it:

Suggested change
// Add to imports at line 8:
import { moveTo, beginSyncUpdate, endSyncUpdate, reset as ansiReset, stripAnsiControl, clearScreen } from '../utils/ansi.js';

// Update line 105:
this._terminal.writeSync(clearScreen + '\x1b[H');

Keep the \x1b[H (cursor home) hardcoded as there is no constant defined for it.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/src/terminal/Renderer.ts` at line 105, The code in Renderer.ts
hardcodes the ANSI escape sequence for clearing the screen in the writeSync
method call. Instead of using a magic string, import the clearScreen constant
that is already defined in the utils/ansi.js module and use it in place of the
hardcoded sequence. Add clearScreen to the existing import statement from
'../utils/ansi.js' (around line 8), then update the writeSync call to use
clearScreen concatenated with the cursor home sequence '\x1b[H' instead of the
combined hardcoded string.

@Karanjot786 Karanjot786 merged commit 0b2b096 into Karanjot786:main Jun 23, 2026
7 of 10 checks passed
@Karanjot786 Karanjot786 added gssoc:approved Approved PR. Earns +50 base points. level:beginner +20 pts. Entry-level task. labels Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core @termuijs/core gssoc:approved Approved PR. Earns +50 base points. level:beginner +20 pts. Entry-level task. needs-star PR author has not starred the repo. type:bug +10 pts. Bug fix.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Renderer fails to clear stale characters when the terminal window is resized smaller

2 participants