Fix garbled text in PowerShell terminal on Windows 10 by disabling OSC 633;E sequence #284298
+7
−5
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.
Description
On Windows 10, the OSC 633;E escape sequence causes a rendering race condition where escaped command text (e.g.,
\x5cfor backslashes) appears in the terminal output, particularly with long commands (>100 characters). This occurs because the terminal incorrectly echoes the escaped content meant for history tracking.Changes
PSConsoleHostReadLinefunction inshellIntegration.ps1to conditionally skip OSC 633;E sequence on Windows 10 (build < 22000)Trade-off: Command line content not reported on Windows 10, but eliminates display corruption. Core shell integration functionality preserved via other OSC sequences.
Original prompt
This section details on the original issue you should resolve
<issue_title>shellIntegration.ps1 caused Python Debugger with Garbled Text</issue_title>
<issue_description>
Does this issue occur when all extensions are disabled?: Yes
Local Configuration
Operating System: Windows 10 Pro 22H2 (19045.6093)
VSCode Version: 1.106.3
PowerShell Version: 7.5.2
📋 Table of Contents
Problem Description
Symptoms
When using the integrated terminal in VSCode to run a Python debugging session via F5 or execute a long command, the terminal displays a string of garbled text. For example:
Note the garbled output on the second line:
launcher' '3729' '--' 'C:\x5cUsers\x5cSeanL\x5cDesktop\x5ca.py'. This line of garbled text is overlaid on the script's output, obscuring readability during debugging, although it does not affect the script's execution.It's important to note that this issue is not consistently reproducible with every run of the same file.
Key Characteristics
\is escaped as\x5c.-NoProfileflag.-NoProfileis not a viable workaround as it breaks Conda environment activation and other profile-dependent functionalities.Problem Analysis
Trigger Conditions
Why only in VSCode?
VSCode's Shell Integration feature automatically injects a script,
shellIntegration.ps1, to enhance the terminal experience (command tracking, output capturing, smart navigation, etc.). This script communicates with VSCode using OSC (Operating System Command) escape sequences.Other terminals (Windows Terminal, ConEmu, etc.) do not inject this script, hence the problem is specific to the VSCode integrated terminal.
Root Cause
Technical Mechanism
OSC 633 Control Sequence
VSCode Shell Integration uses the OSC 633 series sequences to track command execution:
Detailed Explanation
Inside the
PSConsoleHostReadLinefunction ofshellIntegration.ps1(around lines 195-222), the following logic is implemented: