Skip to content

Commit ab8bfa3

Browse files
Replace `e with $([char]0x1b) (#1961)
This allows shell integration to work with Windows PowerShell, as the only problem seemed to be use of `e, which was an escape character added only to PowerShell Core, but the `[char]` equivalent works fine.
1 parent 2cc173e commit ab8bfa3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,12 @@ private Task EnableShellIntegrationAsync(CancellationToken cancellationToken)
531531
if ($Global:__LastHistoryId -ne -1) {
532532
if ($LastHistoryEntry.Id -eq $Global:__LastHistoryId) {
533533
# Don't provide a command line or exit code if there was no history entry (eg. ctrl+c, enter on no command)
534-
$Result = ""`e]633;E`a""
535-
$Result += ""`e]633;D`a""
534+
$Result = ""$([char]0x1b)]633;E`a""
535+
$Result += ""$([char]0x1b)]633;D`a""
536536
} else {
537537
# Command finished command line
538538
# OSC 633 ; A ; <CommandLine?> ST
539-
$Result = ""`e]633;E;""
539+
$Result = ""$([char]0x1b)]633;E;""
540540
# Sanitize the command line to ensure it can get transferred to the terminal and can be parsed
541541
# correctly. This isn't entirely safe but good for most cases, it's important for the Pt parameter
542542
# to only be composed of _printable_ characters as per the spec.
@@ -549,27 +549,27 @@ private Task EnableShellIntegrationAsync(CancellationToken cancellationToken)
549549
$Result += ""`a""
550550
# Command finished exit code
551551
# OSC 633 ; D [; <ExitCode>] ST
552-
$Result += ""`e]633;D;$FakeCode`a""
552+
$Result += ""$([char]0x1b)]633;D;$FakeCode`a""
553553
}
554554
}
555555
# Prompt started
556556
# OSC 633 ; A ST
557-
$Result += ""`e]633;A`a""
557+
$Result += ""$([char]0x1b)]633;A`a""
558558
# Current working directory
559559
# OSC 633 ; <Property>=<Value> ST
560-
$Result += if($pwd.Provider.Name -eq 'FileSystem'){""`e]633;P;Cwd=$($pwd.ProviderPath)`a""}
560+
$Result += if($pwd.Provider.Name -eq 'FileSystem'){""$([char]0x1b)]633;P;Cwd=$($pwd.ProviderPath)`a""}
561561
# Before running the original prompt, put $? back to what it was:
562562
if ($FakeCode -ne 0) { Write-Error ""failure"" -ea ignore }
563563
# Run the original prompt
564564
$Result += $Global:__VSCodeOriginalPrompt.Invoke()
565565
# Write command started
566-
$Result += ""`e]633;B`a""
566+
$Result += ""$([char]0x1b)]633;B`a""
567567
$Global:__LastHistoryId = $LastHistoryEntry.Id
568568
return $Result
569569
}
570570
571571
# Set IsWindows property
572-
Write-Host -NoNewLine ""`e]633;P;IsWindows=$($IsWindows)`a""
572+
Write-Host -NoNewLine ""$([char]0x1b)]633;P;IsWindows=$($IsWindows)`a""
573573
574574
# Set always on key handlers which map to default VS Code keybindings
575575
function Set-MappedKeyHandler {

0 commit comments

Comments
 (0)