Skip to content

Commit 8c172fc

Browse files
authored
Merge pull request microsoft#210831 from microsoft/tyriar/revert/si
Revert "Merge pull request microsoft#209136 from cpendery/fix/improve-marker-p…
2 parents 73a2c10 + 521e3f8 commit 8c172fc

File tree

6 files changed

+19
-81
lines changed

6 files changed

+19
-81
lines changed

src/vs/platform/terminal/common/capabilities/capabilities.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ export interface ICommandDetectionCapability {
182182
readonly onCurrentCommandInvalidated: Event<ICommandInvalidationRequest>;
183183
setContinuationPrompt(value: string): void;
184184
setCwd(value: string): void;
185-
setPromptHeight(value: number): void;
186185
setIsWindowsPty(value: boolean): void;
187186
setIsCommandStorageDisabled(): void;
188187
/**

src/vs/platform/terminal/common/capabilities/commandDetection/terminalCommand.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ export class TerminalCommand implements ITerminalCommand {
213213

214214
export interface ICurrentPartialCommand {
215215
promptStartMarker?: IMarker;
216-
promptHeight?: number;
217216

218217
commandStartMarker?: IMarker;
219218
commandStartX?: number;
@@ -245,23 +244,12 @@ export interface ICurrentPartialCommand {
245244
*/
246245
isInvalid?: boolean;
247246

248-
/**
249-
* Whether the command start marker has been adjusted on Windows.
250-
*/
251-
isAdjusted?: boolean;
252-
253-
/**
254-
* Whether the command start marker adjustment has been attempt on new terminal input.
255-
*/
256-
isInputAdjusted?: boolean;
257-
258247
getPromptRowCount(): number;
259248
getCommandRowCount(): number;
260249
}
261250

262251
export class PartialTerminalCommand implements ICurrentPartialCommand {
263252
promptStartMarker?: IMarker;
264-
promptHeight?: number;
265253

266254
commandStartMarker?: IMarker;
267255
commandStartX?: number;

src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ export class CommandDetectionCapability extends Disposable implements ICommandDe
154154
};
155155
this._register(this._terminal.onResize(e => this._handleResize(e)));
156156
this._register(this._terminal.onCursorMove(() => this._handleCursorMove()));
157-
this._register(this._terminal.onData(() => this._handleInput()));
158157
}
159158

160159
private _handleResize(e: { cols: number; rows: number }) {
@@ -208,10 +207,6 @@ export class CommandDetectionCapability extends Disposable implements ICommandDe
208207
this._cwd = value;
209208
}
210209

211-
setPromptHeight(value: number) {
212-
this._currentCommand.promptHeight = value;
213-
}
214-
215210
setIsWindowsPty(value: boolean) {
216211
if (value && !(this._ptyHeuristics.value instanceof WindowsPtyHeuristics)) {
217212
const that = this;
@@ -285,10 +280,6 @@ export class CommandDetectionCapability extends Disposable implements ICommandDe
285280
return undefined;
286281
}
287282

288-
private _handleInput(): void {
289-
this._ptyHeuristics.value.handleInput();
290-
}
291-
292283
handlePromptStart(options?: IHandleCommandOptions): void {
293284
// Adjust the last command's finished marker when needed. The standard position for the
294285
// finished marker `D` to appear is at the same position as the following prompt started
@@ -508,8 +499,6 @@ class UnixPtyHeuristics extends Disposable {
508499
}));
509500
}
510501

511-
handleInput() { }
512-
513502
handleCommandStart(options?: IHandleCommandOptions) {
514503
this._hooks.commitCommandFinished();
515504

@@ -663,28 +652,6 @@ class WindowsPtyHeuristics extends Disposable {
663652
}
664653
}
665654

666-
/**
667-
* Attempt to adjust the command start marker when input is handled for the first time.
668-
*/
669-
handleInput() {
670-
const currentY = this._terminal.buffer.active.baseY + this._terminal.buffer.active.cursorY;
671-
672-
const hasWrappingInPrompt = Array.from({ length: (this._capability.currentCommand.promptHeight ?? 0) + 1 }, (_, i) => currentY - i).find(y => this._terminal.buffer.active.getLine(y)?.isWrapped) !== undefined;
673-
const hasActiveCommand = this._capability.currentCommand.commandStartX !== undefined && this._capability.currentCommand.commandExecutedX === undefined;
674-
const hasAdjusted = this._capability.currentCommand.isAdjusted === true || this._capability.currentCommand.isInputAdjusted === true;
675-
676-
if (!hasActiveCommand || hasAdjusted || hasWrappingInPrompt) {
677-
return;
678-
}
679-
this._capability.currentCommand.isInputAdjusted = true;
680-
this._logService.debug('CommandDetectionCapability#handleInput attempting start marker adjustment');
681-
682-
this._tryAdjustCommandStartMarkerScannedLineCount = 0;
683-
this._tryAdjustCommandStartMarkerPollCount = 0;
684-
this._tryAdjustCommandStartMarkerScheduler = new RunOnceScheduler(() => this._tryAdjustCommandStartMarker(this._terminal.registerMarker(0)!), AdjustCommandStartMarkerConstants.Interval);
685-
this._tryAdjustCommandStartMarkerScheduler.schedule();
686-
}
687-
688655
handleCommandStart() {
689656
this._capability.currentCommand.commandStartX = this._terminal.buffer.active.cursorX;
690657

@@ -746,24 +713,21 @@ class WindowsPtyHeuristics extends Disposable {
746713
if (prompt) {
747714
const adjustedPrompt = typeof prompt === 'string' ? prompt : prompt.prompt;
748715
this._capability.currentCommand.commandStartMarker = this._terminal.registerMarker(0)!;
749-
750-
// Adjust the prompt start marker to the command start marker
751-
this._logService.debug('CommandDetectionCapability#_tryAdjustCommandStartMarker adjusted promptStart', `${this._capability.currentCommand.promptStartMarker?.line} -> ${this._capability.currentCommand.commandStartMarker.line}`);
752-
this._capability.currentCommand.promptStartMarker?.dispose();
753-
this._capability.currentCommand.promptStartMarker = cloneMarker(this._terminal, this._capability.currentCommand.commandStartMarker, -((this._capability.currentCommand.promptHeight ?? 1) - 1));
754-
755-
// Adjust the last command if it's not in the same position as the following
756-
// prompt start marker
757-
const lastCommand = this._capability.commands.at(-1);
758-
if (lastCommand && this._capability.currentCommand.commandStartMarker.line !== lastCommand.endMarker?.line) {
759-
lastCommand.endMarker?.dispose();
760-
lastCommand.endMarker = cloneMarker(this._terminal, this._capability.currentCommand.commandStartMarker, -((this._capability.currentCommand.promptHeight ?? 1) - 1));
716+
if (typeof prompt === 'object' && prompt.likelySingleLine) {
717+
this._logService.debug('CommandDetectionCapability#_tryAdjustCommandStartMarker adjusted promptStart', `${this._capability.currentCommand.promptStartMarker?.line} -> ${this._capability.currentCommand.commandStartMarker.line}`);
718+
this._capability.currentCommand.promptStartMarker?.dispose();
719+
this._capability.currentCommand.promptStartMarker = cloneMarker(this._terminal, this._capability.currentCommand.commandStartMarker);
720+
// Adjust the last command if it's not in the same position as the following
721+
// prompt start marker
722+
const lastCommand = this._capability.commands.at(-1);
723+
if (lastCommand && this._capability.currentCommand.commandStartMarker.line !== lastCommand.endMarker?.line) {
724+
lastCommand.endMarker?.dispose();
725+
lastCommand.endMarker = cloneMarker(this._terminal, this._capability.currentCommand.commandStartMarker);
726+
}
761727
}
762-
763728
// use the regex to set the position as it's possible input has occurred
764729
this._capability.currentCommand.commandStartX = adjustedPrompt.length;
765730
this._logService.debug('CommandDetectionCapability#_tryAdjustCommandStartMarker adjusted commandStart', `${start.line} -> ${this._capability.currentCommand.commandStartMarker.line}:${this._capability.currentCommand.commandStartX}`);
766-
this._capability.currentCommand.isAdjusted = true;
767731
this._flushPendingHandleCommandStartTask();
768732
return;
769733
}
@@ -1085,7 +1049,5 @@ function getXtermLineContent(buffer: IBuffer, lineStart: number, lineEnd: number
10851049
}
10861050

10871051
function cloneMarker(xterm: Terminal, marker: IXtermMarker, offset: number = 0): IXtermMarker | undefined {
1088-
const cursorY = xterm.buffer.active.baseY + xterm.buffer.active.cursorY;
1089-
const cursorYOffset = marker.line - cursorY + offset;
1090-
return xterm.registerMarker((cursorY + cursorYOffset) < 0 ? -cursorY : cursorYOffset);
1052+
return xterm.registerMarker(marker.line - (xterm.buffer.active.baseY + xterm.buffer.active.cursorY) + offset);
10911053
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,6 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
403403
this.capabilities.get(TerminalCapability.CommandDetection)?.setIsCommandStorageDisabled();
404404
return true;
405405
}
406-
case 'PromptHeight': {
407-
this.capabilities.get(TerminalCapability.CommandDetection)?.setPromptHeight(parseInt(value));
408-
return true;
409-
}
410406
}
411407
}
412408
case VSCodeOscPt.SetMark: {

src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,6 @@ __vsc_update_cwd() {
182182
builtin printf '\e]633;P;Cwd=%s\a' "$(__vsc_escape_value "$__vsc_cwd")"
183183
}
184184

185-
__vsc_update_prompt_height() {
186-
__vsc_prompt_height="$(("$(builtin printf "%s" "${PS1@P}" | wc -l)" + 1))"
187-
builtin printf '\e]633;P;PromptHeight=%s\a' "$(__vsc_escape_value "$__vsc_prompt_height")"
188-
}
189-
190185
__vsc_command_output_start() {
191186
builtin printf '\e]633;E;%s;%s\a' "$(__vsc_escape_value "${__vsc_current_command}")" $__vsc_nonce
192187
builtin printf '\e]633;C\a'
@@ -234,7 +229,6 @@ __vsc_precmd() {
234229
__vsc_command_complete "$__vsc_status"
235230
__vsc_current_command=""
236231
__vsc_update_prompt
237-
__vsc_update_prompt_height
238232
__vsc_first_prompt=1
239233
}
240234

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,17 @@ if ($env:VSCODE_ENV_APPEND) {
5252
function Global:__VSCode-Escape-Value([string]$value) {
5353
# NOTE: In PowerShell v6.1+, this can be written `$value -replace '…', { … }` instead of `[regex]::Replace`.
5454
# Replace any non-alphanumeric characters.
55-
[regex]::Replace($value, "[$([char]0x1b)\\\n;]", { param($match)
55+
$Result = [regex]::Replace($value, '[\\\n;]', { param($match)
5656
# Encode the (ascii) matches as `\x<hex>`
5757
-Join (
5858
[System.Text.Encoding]::UTF8.GetBytes($match.Value) | ForEach-Object { '\x{0:x2}' -f $_ }
5959
)
6060
})
61+
# `e is only availabel in pwsh 6+
62+
if ($PSVersionTable.PSVersion.Major -lt 6) {
63+
$Result = $Result -replace "`e", '\x1b'
64+
}
65+
$Result
6166
}
6267

6368
function Global:Prompt() {
@@ -90,13 +95,7 @@ function Global:Prompt() {
9095
Write-Error "failure" -ea ignore
9196
}
9297
# Run the original prompt
93-
$OriginalPrompt += $Global:__VSCodeOriginalPrompt.Invoke()
94-
$Result += $OriginalPrompt
95-
96-
# Prompt height
97-
# OSC 633 ; <Property>=<Value> ST
98-
$Result += "$([char]0x1b)]633;P;PromptHeight=$(__VSCode-Escape-Value ($OriginalPrompt -Split '\n').Count)`a"
99-
98+
$Result += $Global:__VSCodeOriginalPrompt.Invoke()
10099
# Write command started
101100
$Result += "$([char]0x1b)]633;B`a"
102101
$Global:__LastHistoryId = $LastHistoryEntry.Id

0 commit comments

Comments
 (0)