Support zsh's RPROMPT

Fixes #140928
This commit is contained in:
Daniel Imms
2022-03-18 06:38:34 -07:00
parent b87e743eb3
commit 680b20a577
4 changed files with 49 additions and 1 deletions
@@ -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;
@@ -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++) {
@@ -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 ; <Property>=<Value> 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) {
@@ -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
}