Skip to content

Commit d60e424

Browse files
committed
Report 633;E before 633;C in pwsh
1 parent 82d8ed0 commit d60e424

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ const enum VSCodeOscPt {
9797
/**
9898
* Explicitly set the command line. This helps workaround performance and reliability problems
9999
* with parsing out the command, such as conpty not guaranteeing the position of the sequence or
100-
* the shell not guaranteeing that the entire command is even visible.
100+
* the shell not guaranteeing that the entire command is even visible. Ideally this is called
101+
* immediately before {@link CommandExecuted}, immediately before {@link CommandFinished} will
102+
* also work but that means terminal will only know the accurate command line when the command is
103+
* finished.
101104
*
102105
* The command line can escape ascii characters using the `\xAB` format, where AB are the
103106
* hexadecimal representation of the character code (case insensitive), and escape the `\`

src/vs/workbench/contrib/terminal/browser/media/shellIntegration.ps1

+18-19
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,14 @@ function Global:Prompt() {
6363
# error when $LastHistoryEntry is null, and is not otherwise useful.
6464
Set-StrictMode -Off
6565
$LastHistoryEntry = Get-History -Count 1
66+
$Result = ""
6667
# Skip finishing the command if the first command has not yet started
6768
if ($Global:__LastHistoryId -ne -1) {
6869
if ($LastHistoryEntry.Id -eq $Global:__LastHistoryId) {
6970
# Don't provide a command line or exit code if there was no history entry (eg. ctrl+c, enter on no command)
70-
$Result = "$([char]0x1b)]633;E`a"
7171
$Result += "$([char]0x1b)]633;D`a"
7272
}
7373
else {
74-
# Command finished command line
75-
# OSC 633 ; E ; <CommandLine?> ; <Nonce?> ST
76-
$Result = "$([char]0x1b)]633;E;"
77-
# Sanitize the command line to ensure it can get transferred to the terminal and can be parsed
78-
# correctly. This isn't entirely safe but good for most cases, it's important for the Pt parameter
79-
# to only be composed of _printable_ characters as per the spec.
80-
if ($LastHistoryEntry.CommandLine) {
81-
$CommandLine = $LastHistoryEntry.CommandLine
82-
}
83-
else {
84-
$CommandLine = ""
85-
}
86-
$Result += $(__VSCode-Escape-Value $CommandLine)
87-
$Result += ";$Nonce"
88-
$Result += "`a"
8974
# Command finished exit code
9075
# OSC 633 ; D [; <ExitCode>] ST
9176
$Result += "$([char]0x1b)]633;D;$FakeCode`a"
@@ -114,10 +99,24 @@ function Global:Prompt() {
11499
if (Get-Module -Name PSReadLine) {
115100
$__VSCodeOriginalPSConsoleHostReadLine = $function:PSConsoleHostReadLine
116101
function Global:PSConsoleHostReadLine {
117-
$tmp = $__VSCodeOriginalPSConsoleHostReadLine.Invoke()
102+
$CommandLine = $__VSCodeOriginalPSConsoleHostReadLine.Invoke()
103+
104+
# Command line
105+
# OSC 633 ; E ; <CommandLine?> ; <Nonce?> ST
106+
$Result = "$([char]0x1b)]633;E;"
107+
$Result += $(__VSCode-Escape-Value $CommandLine)
108+
$Result += ";$Nonce"
109+
$Result += "`a"
110+
[Console]::Write($Result)
111+
112+
# Command executed
113+
# OSC 633 ; C ST
114+
$Result += "$([char]0x1b)]633;C`a"
115+
118116
# Write command executed sequence directly to Console to avoid the new line from Write-Host
119-
[Console]::Write("$([char]0x1b)]633;C`a")
120-
$tmp
117+
[Console]::Write($Result)
118+
119+
$CommandLine
121120
}
122121
}
123122

src/vscode-dts/vscode.proposed.terminalShellIntegration.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ declare module 'vscode' {
2222
* fired.
2323
* - It may be inaccurate initially if the command line is pulled from the buffer directly
2424
* via the [`OSC 633/133 ; A`, `B` and `C` sequences](https://code.visualstudio.com/docs/terminal/shell-integration#_vs-code-custom-sequences-osc-633-st).
25+
* - It may contain line continuation characters and/or parts of the right prompt.
2526
* - It may be inaccurate if the shell integration does not support command line reporting
2627
* via the [`OSC 633 ; E` sequence](https://code.visualstudio.com/docs/terminal/shell-integration#_vs-code-custom-sequences-osc-633-st).
2728
*/

0 commit comments

Comments
 (0)