mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-18 18:03:19 +01:00
@@ -181,7 +181,7 @@ export interface ICommandDetectionCapability {
|
||||
readonly onCommandInvalidated: Event<ITerminalCommand[]>;
|
||||
readonly onCurrentCommandInvalidated: Event<ICommandInvalidationRequest>;
|
||||
setContinuationPrompt(value: string): void;
|
||||
setPromptTerminator(value: string): void;
|
||||
setPromptTerminator(value: string, lastPromptLine: string): void;
|
||||
setCwd(value: string): void;
|
||||
setIsWindowsPty(value: boolean): void;
|
||||
setIsCommandStorageDisabled(): void;
|
||||
|
||||
@@ -54,6 +54,7 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
|
||||
|
||||
private _commandStartMarker: IMarker | undefined;
|
||||
private _commandStartX: number = 0;
|
||||
private _lastPromptLine: string | undefined;
|
||||
private _continuationPrompt: string | undefined;
|
||||
|
||||
private _lastUserInput: string = '';
|
||||
@@ -117,6 +118,11 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
|
||||
this._continuationPrompt = value;
|
||||
}
|
||||
|
||||
setLastPromptLine(value: string): void {
|
||||
this._lastPromptLine = value;
|
||||
this._sync();
|
||||
}
|
||||
|
||||
setConfidentCommandLine(value: string): void {
|
||||
if (this._value !== value) {
|
||||
this._value = value;
|
||||
@@ -153,6 +159,17 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
|
||||
this._cursorIndex = 0;
|
||||
this._onDidStartInput.fire(this._createStateObject());
|
||||
this._onDidChangeInput.fire(this._createStateObject());
|
||||
|
||||
// Trigger a sync if prompt terminator is set as that could adjust the command start X
|
||||
if (this._lastPromptLine) {
|
||||
if (this._commandStartX !== this._lastPromptLine.length) {
|
||||
const line = this._xterm.buffer.active.getLine(this._commandStartMarker.line);
|
||||
if (line?.translateToString(true).startsWith(this._lastPromptLine)) {
|
||||
this._commandStartX = this._lastPromptLine.length;
|
||||
this._sync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _handleCommandExecuted() {
|
||||
@@ -190,6 +207,9 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('commandStartX', this._commandStartX);
|
||||
console.log('promptTerminator', this._lastPromptLine);
|
||||
|
||||
const buffer = this._xterm.buffer.active;
|
||||
let line = buffer.getLine(commandStartY);
|
||||
const commandLine = line?.translateToString(true, this._commandStartX);
|
||||
|
||||
@@ -205,6 +205,13 @@ export class CommandDetectionCapability extends Disposable implements ICommandDe
|
||||
this._promptInputModel.setContinuationPrompt(value);
|
||||
}
|
||||
|
||||
// TODO: Simplify this, can everything work off the last line?
|
||||
setPromptTerminator(promptTerminator: string, lastPromptLine: string) {
|
||||
this._logService.debug('CommandDetectionCapability#setPromptTerminator', promptTerminator);
|
||||
this._promptTerminator = promptTerminator;
|
||||
this._promptInputModel.setLastPromptLine(lastPromptLine);
|
||||
}
|
||||
|
||||
setCwd(value: string) {
|
||||
this._cwd = value;
|
||||
}
|
||||
@@ -454,11 +461,6 @@ export class CommandDetectionCapability extends Disposable implements ICommandDe
|
||||
this._onCommandFinished.fire(newCommand);
|
||||
}
|
||||
}
|
||||
|
||||
setPromptTerminator(promptTerminator: string) {
|
||||
this._logService.debug('CommandDetectionCapability#setPromptTerminator', promptTerminator);
|
||||
this._promptTerminator = promptTerminator;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -484,10 +484,10 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
|
||||
if (!this._terminal) {
|
||||
return;
|
||||
}
|
||||
const lastPromptLine = prompt.substring(prompt.lastIndexOf('\n')).trim();
|
||||
const promptTerminator = lastPromptLine.substring(lastPromptLine.lastIndexOf(' ')).trim();
|
||||
const lastPromptLine = prompt.substring(prompt.lastIndexOf('\n') + 1);
|
||||
const promptTerminator = lastPromptLine.substring(lastPromptLine.lastIndexOf(' '));
|
||||
if (promptTerminator) {
|
||||
this._createOrGetCommandDetection(this._terminal).setPromptTerminator(promptTerminator);
|
||||
this._createOrGetCommandDetection(this._terminal).setPromptTerminator(promptTerminator, lastPromptLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user