Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

putty-style ED2 sequence handling as terminal option #5224

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/common/InputHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,37 @@ describe('InputHandler', () => {
inputHandler.eraseInLine(Params.fromArray([2]));
assert.equal(bufferService.buffer.lines.get(2)!.isWrapped, false);
});
it('ED2 with scrollOnDisplayErase turned on', async () => {
const inputHandler = new TestInputHandler(
bufferService,
new MockCharsetService(),
new MockCoreService(),
new MockLogService(),
new MockOptionsService({ scrollOnDisplayErase: true }),
new MockOscLinkService(),
new MockCoreMouseService(),
new MockUnicodeService()
);
const aLine = Array(bufferService.cols + 1).join('a');
// add 2 full lines of text.
await inputHandler.parseP(aLine);
await inputHandler.parseP(aLine);

inputHandler.eraseInDisplay(Params.fromArray([2]));
// those 2 lines should have been pushed to scrollback.
assert.equal(bufferService.rows + 2, bufferService.buffer.lines.length);
assert.equal(bufferService.buffer.ybase, 2);
assert.equal(bufferService.buffer.lines.get(0)?.translateToString(), aLine);
assert.equal(bufferService.buffer.lines.get(1)?.translateToString(), aLine);

// Move to last line and add more text.
bufferService.buffer.y = bufferService.rows - 1;
bufferService.buffer.x = 0;
await inputHandler.parseP(aLine);
inputHandler.eraseInDisplay(Params.fromArray([2]));
// Screen should have been scrolled by a full screen size.
assert.equal(bufferService.rows * 2 + 2, bufferService.buffer.lines.length);
});
it('eraseInDisplay', async () => {
const bufferService = new MockBufferService(80, 7);
const inputHandler = new TestInputHandler(
Expand Down
25 changes: 20 additions & 5 deletions src/common/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1220,12 +1220,27 @@ export class InputHandler extends Disposable implements IInputHandler {
this._dirtyRowTracker.markDirty(0);
break;
case 2:
j = this._bufferService.rows;
this._dirtyRowTracker.markDirty(j - 1);
while (j--) {
this._resetBufferLine(j, respectProtect);
if (this._optionsService.rawOptions.scrollOnDisplayErase) {
j = this._bufferService.rows;
this._dirtyRowTracker.markRangeDirty(0, j - 1);
while (j--) {
const currentLine = this._activeBuffer.lines.get(this._activeBuffer.ybase + j);
if (currentLine?.getTrimmedLength()) {
break;
}
}
for (; j >= 0; j--) {
this._bufferService.scroll(this._eraseAttrData());
}
}
else {
j = this._bufferService.rows;
this._dirtyRowTracker.markDirty(j - 1);
while (j--) {
this._resetBufferLine(j, respectProtect);
}
this._dirtyRowTracker.markDirty(0);
}
this._dirtyRowTracker.markDirty(0);
break;
case 3:
// Clear scrollback (everything not in viewport)
Expand Down
3 changes: 2 additions & 1 deletion src/common/services/OptionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export const DEFAULT_OPTIONS: Readonly<Required<ITerminalOptions>> = {
convertEol: false,
termName: 'xterm',
cancelEvents: false,
overviewRuler: {}
overviewRuler: {},
scrollOnDisplayErase: false
};

const FONT_WEIGHT_OPTIONS: Extract<FontWeight, string>[] = ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'];
Expand Down
1 change: 1 addition & 0 deletions src/common/services/Services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export interface ITerminalOptions {
windowOptions?: IWindowOptions;
wordSeparator?: string;
overviewRuler?: IOverviewRulerOptions;
scrollOnDisplayErase?: boolean;

[key: string]: any;
cancelEvents: boolean;
Expand Down
7 changes: 7 additions & 0 deletions typings/xterm-headless.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ declare module '@xterm/headless' {
* All features are disabled by default for security reasons.
*/
windowOptions?: IWindowOptions;

/**
* If enabled ED2 (clear screen) escape sequence will push
* erased text to scrollback.
* This emulates PuTTY default clear screen behavior.
*/
scrollOnDisplayErase?: boolean;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions typings/xterm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ declare module '@xterm/xterm' {
* decorations underneath the scroll bar.
*/
overviewRuler?: IOverviewRulerOptions;

/**
* If enabled ED2 (clear screen) escape sequence will push
* erased text to scrollback.
* This emulates PuTTY default clear screen behavior.
*/
scrollOnDisplayErase?: boolean;
}

/**
Expand Down
Loading