Inline terminal rendering parity with the VSCode Terminal #11361
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.