diff --git a/src/vs/platform/terminal/common/capabilities/capabilities.ts b/src/vs/platform/terminal/common/capabilities/capabilities.ts index f87d3c7ffdf..a77407629a1 100644 --- a/src/vs/platform/terminal/common/capabilities/capabilities.ts +++ b/src/vs/platform/terminal/common/capabilities/capabilities.ts @@ -97,6 +97,8 @@ export interface ICommandDetectionCapability { handlePromptStart(): void; handleContinuationStart(): void; handleContinuationEnd(): void; + handleRightPromptStart(): void; + handleRightPromptEnd(): void; handleCommandStart(): void; handleCommandExecuted(): void; handleCommandFinished(exitCode: number | undefined): void; diff --git a/src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts b/src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts index bea3d7ba028..3572ec6bf51 100644 --- a/src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts +++ b/src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts @@ -20,6 +20,9 @@ export interface ICurrentPartialCommand { commandStartMarker?: IMarker; commandStartX?: number; + commandRightPromptStartX?: number; + commandRightPromptEndX?: number; + commandLines?: IMarker; commandExecutedMarker?: IMarker; @@ -102,6 +105,16 @@ export class CommandDetectionCapability implements ICommandDetectionCapability { this._logService.debug('CommandDetectionCapability#handleContinuationEnd', this._currentCommand.continuations[this._currentCommand.continuations.length - 1]); } + handleRightPromptStart(): void { + this._currentCommand.commandRightPromptStartX = this._terminal.buffer.active.cursorX; + this._logService.debug('CommandDetectionCapability#handleRightPromptStart', this._currentCommand.commandRightPromptStartX); + } + + handleRightPromptEnd(): void { + this._currentCommand.commandRightPromptEndX = this._terminal.buffer.active.cursorX; + this._logService.debug('CommandDetectionCapability#handleRightPromptEnd', this._currentCommand.commandRightPromptEndX); + } + handleCommandStart(): void { this._currentCommand.commandStartX = this._terminal.buffer.active.cursorX; @@ -155,7 +168,7 @@ export class CommandDetectionCapability implements ICommandDetectionCapability { } // Calculate the command - this._currentCommand.command = this._terminal.buffer.active.getLine(this._currentCommand.commandStartMarker.line)?.translateToString(true, this._currentCommand.commandStartX); + this._currentCommand.command = this._terminal.buffer.active.getLine(this._currentCommand.commandStartMarker.line)?.translateToString(true, this._currentCommand.commandStartX, this._currentCommand.commandRightPromptStartX).trim(); let y = this._currentCommand.commandStartMarker.line + 1; const commandExecutedLine = this._currentCommand.commandExecutedMarker.line; for (; y < commandExecutedLine; y++) { diff --git a/src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts b/src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts index e886b19cb6d..7312b958eb3 100644 --- a/src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts +++ b/src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts @@ -98,6 +98,16 @@ const enum VSCodeOscPt { */ ContinuationEnd = 'G', + /** + * The start of the right prompt. + */ + RightPromptStart = 'H', + + /** + * The end of the right prompt. + */ + RightPromptEnd = 'I', + /** * Set an arbitrary property: `OSC 633 ; P ; = ST`, only known properties will * be handled. @@ -168,6 +178,14 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati this._createOrGetCommandDetection(this._terminal).handleContinuationEnd(); return true; } + case VSCodeOscPt.RightPromptStart: { + this._createOrGetCommandDetection(this._terminal).handleRightPromptStart(); + return true; + } + case VSCodeOscPt.RightPromptEnd: { + this._createOrGetCommandDetection(this._terminal).handleRightPromptEnd(); + return true; + } case VSCodeOscPt.Property: { const [key, value] = args[0].split('='); switch (key) { diff --git a/src/vs/workbench/contrib/terminal/browser/media/shellIntegration.zsh b/src/vs/workbench/contrib/terminal/browser/media/shellIntegration.zsh index d358d20ec7c..6f380da1fd9 100644 --- a/src/vs/workbench/contrib/terminal/browser/media/shellIntegration.zsh +++ b/src/vs/workbench/contrib/terminal/browser/media/shellIntegration.zsh @@ -42,6 +42,14 @@ continuation_end() { printf "\033]633;G\007" } +rprompt_start() { + printf "\033]633;H\007" +} + +rprompt_end() { + printf "\033]633;I\007" +} + command_complete() { local HISTORY_ID=$(history | tail -n1 | awk '{print $1;}') if [[ "$HISTORY_ID" == "$LAST_HISTORY_ID" ]]; then @@ -58,6 +66,10 @@ update_prompt() { IN_COMMAND_EXECUTION="" PS1="%{$(prompt_start)%}$PREFIX$PS1%{$(prompt_end)%}" PS2="%{$(continuation_start)%}$PS2%{$(continuation_end)%}" + if [ -n "$RPROMPT" ]; then + PRIOR_RPROMPT="$RPROMPT" + RPROMPT="%{$(rprompt_start)%}$RPROMPT%{$(rprompt_end)%}" + fi } precmd() { @@ -78,6 +90,9 @@ precmd() { preexec() { PS1="$PRIOR_PROMPT" + if [ -n "$RPROMPT" ]; then + RPROMPT="$PRIOR_RPROMPT" + fi IN_COMMAND_EXECUTION="1" command_output_start }