Skip to content

Commit

Permalink
Clear viewport commands in partial detection on CSI 2/3 J
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar authored and gabritto committed Mar 25, 2022
1 parent af99cbd commit 88da524
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export class PartialCommandDetectionCapability implements IPartialCommandDetecti
private readonly _terminal: Terminal,
) {
this._terminal.onData(e => this._onData(e));
this._terminal.parser.registerCsiHandler({ final: 'J' }, params => {
if (params.length >= 1 && (params[0] === 2 || params[0] === 3)) {
this._clearCommandsInViewport();
}
// We don't want to override xterm.js' default behavior, just augment it
return false;
});
}

private _onData(data: string): void {
Expand All @@ -54,4 +61,17 @@ export class PartialCommandDetectionCapability implements IPartialCommandDetecti
}
}
}

private _clearCommandsInViewport(): void {
// Find the number of commands on the tail end of the array that are within the viewport
let count = 0;
for (let i = this._commands.length - 1; i >= 0; i--) {
if (this._commands[i].line < this._terminal.buffer.active.baseY) {
break;
}
count++;
}
// Remove them
this._commands.splice(this._commands.length - count, count);
}
}

0 comments on commit 88da524

Please sign in to comment.