From aaf74e96e29cc5316d49e08935957b1452dcd968 Mon Sep 17 00:00:00 2001 From: Andy Jordan Date: Tue, 22 Nov 2022 11:23:04 -0800 Subject: [PATCH] Replace `e with $([char]0x1b) 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. --- .../Services/PowerShell/Host/PsesInternalHost.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs index 19b873e19..cf83dd34b 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs @@ -531,12 +531,12 @@ private Task EnableShellIntegrationAsync(CancellationToken cancellationToken) if ($Global:__LastHistoryId -ne -1) { if ($LastHistoryEntry.Id -eq $Global:__LastHistoryId) { # Don't provide a command line or exit code if there was no history entry (eg. ctrl+c, enter on no command) - $Result = ""`e]633;E`a"" - $Result += ""`e]633;D`a"" + $Result = ""$([char]0x1b)]633;E`a"" + $Result += ""$([char]0x1b)]633;D`a"" } else { # Command finished command line # OSC 633 ; A ; ST - $Result = ""`e]633;E;"" + $Result = ""$([char]0x1b)]633;E;"" # Sanitize the command line to ensure it can get transferred to the terminal and can be parsed # correctly. This isn't entirely safe but good for most cases, it's important for the Pt parameter # to only be composed of _printable_ characters as per the spec. @@ -549,27 +549,27 @@ private Task EnableShellIntegrationAsync(CancellationToken cancellationToken) $Result += ""`a"" # Command finished exit code # OSC 633 ; D [; ] ST - $Result += ""`e]633;D;$FakeCode`a"" + $Result += ""$([char]0x1b)]633;D;$FakeCode`a"" } } # Prompt started # OSC 633 ; A ST - $Result += ""`e]633;A`a"" + $Result += ""$([char]0x1b)]633;A`a"" # Current working directory # OSC 633 ; = ST - $Result += if($pwd.Provider.Name -eq 'FileSystem'){""`e]633;P;Cwd=$($pwd.ProviderPath)`a""} + $Result += if($pwd.Provider.Name -eq 'FileSystem'){""$([char]0x1b)]633;P;Cwd=$($pwd.ProviderPath)`a""} # Before running the original prompt, put $? back to what it was: if ($FakeCode -ne 0) { Write-Error ""failure"" -ea ignore } # Run the original prompt $Result += $Global:__VSCodeOriginalPrompt.Invoke() # Write command started - $Result += ""`e]633;B`a"" + $Result += ""$([char]0x1b)]633;B`a"" $Global:__LastHistoryId = $LastHistoryEntry.Id return $Result } # Set IsWindows property -Write-Host -NoNewLine ""`e]633;P;IsWindows=$($IsWindows)`a"" +Write-Host -NoNewLine ""$([char]0x1b)]633;P;IsWindows=$($IsWindows)`a"" # Set always on key handlers which map to default VS Code keybindings function Set-MappedKeyHandler {