-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Inline terminal rendering parity with the VSCode Terminal #11361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Fixes RooCodeInc#10699 ## Problem The inline terminal output displayed raw ANSI bracket codes ([1m, [32m, etc.) instead of rendering colors and formatting. This was caused by: 1. Backend: strip-ansi removing the ESC byte but leaving bracket remnants 2. Frontend: CodeBlock/Shiki having no ANSI rendering capability ## Solution 1. Backend: Replace strip-ansi with targeted removal of only VSCode shell integration sequences (OSC 633/133), preserving standard ANSI SGR codes 2. Frontend: Add new TerminalOutput component using ansi-to-html library that converts ANSI sequences to styled HTML spans 3. Map ANSI colors to VSCode terminal theme CSS variables for consistent theming across light/dark themes ## Testing - Verified XSS prevention (escapeXML: true) - Verified theme compatibility - Added unit tests for both backend and frontend changes - Updated existing tests to expect ANSI codes in output Bundle size impact: ~3KB gzipped (ansi-to-html library) Co-authored-by: Zman771 <605281+Zman771@users.noreply.github.com>
…7643938474473035449 fix: render ANSI escape codes in inline terminal output
Found 1 issue to address before merging.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| private stripCursorSequences(text: string): string { | ||
| return text | ||
| .replace(/\x1B\[\d*[ABCDEFGHJ]/g, "") // Remove cursor movement: up, down, forward, back | ||
| .replace(/\x1B\[su/g, "") // Remove cursor position save/restore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: /\x1B\[su/g matches the literal 4-character sequence ESC[su, which is not a real ANSI sequence. Cursor save (ESC[s) and cursor restore (ESC[u) are two separate sequences. This regex will never match either one individually, so these cursor codes will pass through unstripped into the webview output. The fix is to use a character class so the regex matches either letter.
| .replace(/\x1B\[su/g, "") // Remove cursor position save/restore | |
| .replace(/\x1B\[[su]/g, "") // Remove cursor position save/restore |
Fix it with Roo Code or mention @roomote and request a fix.
Related GitHub Issue
Closes: #10699
Description
This PR implements inline terminal rendering parity with the VSCode Terminal, addressing the issue where raw ANSI bracket codes (e.g.,
[32m,[1m) were displayed instead of colors and formatting.Key Changes:
Backend (
src/integrations/terminal/TerminalProcess.ts):strip-ansiusage with a customremoveVSCodeShellIntegrationmethod. This explicitly removes VSCode-specific shell integration sequences (OSC 633, OSC 133) but preserves standard ANSI SGR sequences (colors, formatting).stripCursorSequencesto remove unsupported cursor movement codes (e.g., clear line, move cursor) to keep the output clean for the webview.Frontend (
webview-ui/src/components/chat/TerminalOutput.tsx):TerminalOutputcomponent utilizing theansi-to-htmllibrary.var(--vscode-terminal-ansiGreen)), ensuring the output automatically adapts to the user's active color theme.escapeXML: trueto prevent XSS vulnerabilities from command output.Integration: Updated
CommandExecution.tsxto useTerminalOutputinstead of the genericCodeBlockfor displaying command output.Test Procedure
Backend Unit Tests:
src/integrations/terminal/__tests__/TerminalProcess.test.tsto verify thatremoveVSCodeShellIntegrationstrictly removes OSC sequences while keeping ANSI colors intact, and thatstripCursorSequencesremoves cursor control codes.src/integrations/terminal/__tests__/TerminalProcessExec.bash.spec.tsto assert that simulated terminal commands return string output containing ANSI codes (e.g.,\x1B[31mRed Text\x1B[0m) rather than stripped plain text.Frontend Unit Tests:
webview-ui/src/components/chat/__tests__/TerminalOutput.spec.tsxto verify:Regression Testing:
npm test) to ensure no regressions in existing terminal or chat functionality.Pre-Submission Checklist
Documentation Updates
Additional Notes
ansi-to-htmltowebview-uidependencies (approx. 3KB gzipped impact).escapeXML: truein the converter to sanitize output before rendering viadangerouslySetInnerHTML.Get in Touch
tea_earl_grey_hot
Important
This PR enhances terminal output rendering by preserving ANSI codes, introducing a new
TerminalOutputcomponent, and updating tests for improved functionality and security.strip-ansiwithremoveVSCodeShellIntegrationinTerminalProcess.tsto preserve ANSI SGR sequences while removing VSCode-specific sequences.stripCursorSequencesto remove unsupported cursor movement codes.CommandExecution.tsxto useTerminalOutputfor command output.TerminalOutputcomponent inTerminalOutput.tsxusingansi-to-htmlfor ANSI to HTML conversion.TerminalProcess.test.tsto test ANSI handling functions.TerminalProcessExec.bash.spec.tsto verify ANSI codes are preserved.TerminalOutput.spec.tsxto testTerminalOutputrendering and XSS prevention.CommandExecution.spec.tsxto test integration withTerminalOutput.This description was created by
for 64258da. You can customize this summary. It will automatically update as commits are pushed.