fix: force clear terminal on fullRender to prevent stale artifacts on…#1612
Conversation
📝 WalkthroughWalkthrough
ChangesFull Render Terminal Clear
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Possibly related issues
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
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 Thanks for your contribution to TermUI. |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
packages/core/src/terminal/Renderer.ts
| */ | ||
| fullRender(): void { | ||
| this._screen.invalidate(); | ||
| this._terminal.writeSync('\x1b[2J\x1b[H'); |
There was a problem hiding this comment.
🧩 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=tsRepository: Karanjot786/TermUI
Length of output: 2115
🏁 Script executed:
# Find ANSI constants file
fd -i ansi packages/core/src --type f | head -20Repository: 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 -30Repository: 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.tsRepository: 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 tsRepository: 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.tsRepository: Karanjot786/TermUI
Length of output: 2415
🏁 Script executed:
# Check current imports in Renderer.ts
sed -n '1,30p' packages/core/src/terminal/Renderer.tsRepository: 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.tsRepository: 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.tsRepository: 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.tsRepository: 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.
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