From e9913522ac9982d6172614dfd7fe95a1baaef172 Mon Sep 17 00:00:00 2001 From: meganrogge Date: Fri, 4 Feb 2022 15:53:31 -0600 Subject: [PATCH 1/7] fix buffers not clearing --- src/browser/Terminal.ts | 1 + src/common/buffer/Buffer.ts | 15 ++++++++++++++- src/common/buffer/Types.d.ts | 3 ++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/browser/Terminal.ts b/src/browser/Terminal.ts index fe5c7f79f9..509bb2acf5 100644 --- a/src/browser/Terminal.ts +++ b/src/browser/Terminal.ts @@ -1293,6 +1293,7 @@ export class Terminal extends CoreTerminal implements ITerminal { // Don't clear if it's already clear return; } + this.buffer.clearMarkers(); this.buffer.lines.set(0, this.buffer.lines.get(this.buffer.ybase + this.buffer.y)!); this.buffer.lines.length = 1; this.buffer.ydisp = 0; diff --git a/src/common/buffer/Buffer.ts b/src/common/buffer/Buffer.ts index 02ce7c8168..e348ad4cda 100644 --- a/src/common/buffer/Buffer.ts +++ b/src/common/buffer/Buffer.ts @@ -16,6 +16,7 @@ import { DEFAULT_CHARSET } from 'common/data/Charsets'; import { ExtendedAttrs } from 'common/buffer/AttributeData'; export const MAX_BUFFER_SIZE = 4294967295; // 2^32 - 1 +const enum BufferState { CLEARING = 'clearing' } /** * This class represents a terminal buffer (an internal state of the terminal), where the @@ -43,6 +44,7 @@ export class Buffer implements IBuffer { private _whitespaceCell: ICellData = CellData.fromCharData([0, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_WIDTH, WHITESPACE_CELL_CODE]); private _cols: number; private _rows: number; + private _state: string | undefined; constructor( private _hasScrollback: boolean, @@ -584,6 +586,15 @@ export class Buffer implements IBuffer { return x >= this._cols ? this._cols - 1 : x < 0 ? 0 : x; } + public clearMarkers(): void { + this._state = BufferState.CLEARING; + for (const marker of this.markers) { + marker.dispose(); + } + this.markers = []; + this._state = undefined; + } + public addMarker(y: number): Marker { const marker = new Marker(y); this.markers.push(marker); @@ -615,7 +626,9 @@ export class Buffer implements IBuffer { } private _removeMarker(marker: Marker): void { - this.markers.splice(this.markers.indexOf(marker), 1); + if (this._state !== BufferState.CLEARING) { + this.markers.splice(this.markers.indexOf(marker), 1); + } } public iterator(trimRight: boolean, startIndex?: number, endIndex?: number, startOverscan?: number, endOverscan?: number): IBufferStringIterator { diff --git a/src/common/buffer/Types.d.ts b/src/common/buffer/Types.d.ts index cbf40a03d3..fc97020c31 100644 --- a/src/common/buffer/Types.d.ts +++ b/src/common/buffer/Types.d.ts @@ -10,7 +10,7 @@ import { IEvent } from 'common/EventEmitter'; export type BufferIndex = [number, number]; export interface IBufferStringIteratorResult { - range: {first: number, last: number}; + range: { first: number, last: number }; content: string; } @@ -45,6 +45,7 @@ export interface IBuffer { getNullCell(attr?: IAttributeData): ICellData; getWhitespaceCell(attr?: IAttributeData): ICellData; addMarker(y: number): IMarker; + clearMarkers(): void; } export interface IBufferSet extends IDisposable { From f3bd1e24b73d2db78385b46b574e4b64b1147c88 Mon Sep 17 00:00:00 2001 From: meganrogge Date: Fri, 4 Feb 2022 16:13:20 -0600 Subject: [PATCH 2/7] undo formatting change --- src/common/buffer/Types.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/buffer/Types.d.ts b/src/common/buffer/Types.d.ts index fc97020c31..9259d46d4a 100644 --- a/src/common/buffer/Types.d.ts +++ b/src/common/buffer/Types.d.ts @@ -10,7 +10,7 @@ import { IEvent } from 'common/EventEmitter'; export type BufferIndex = [number, number]; export interface IBufferStringIteratorResult { - range: { first: number, last: number }; + range: {first: number, last: number}; content: string; } From 8999d3948a930da1b74347b15f77ece9b6e242eb Mon Sep 17 00:00:00 2001 From: meganrogge Date: Fri, 4 Feb 2022 17:39:37 -0600 Subject: [PATCH 3/7] fix test and improve name --- src/browser/TestUtils.test.ts | 3 +++ src/common/buffer/Buffer.ts | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/browser/TestUtils.test.ts b/src/browser/TestUtils.test.ts index 8fdf458e6d..ee266e9c6b 100644 --- a/src/browser/TestUtils.test.ts +++ b/src/browser/TestUtils.test.ts @@ -254,6 +254,9 @@ export class MockBuffer implements IBuffer { public getWhitespaceCell(attr?: IAttributeData): ICellData { throw new Error('Method not implemented.'); } + public clearMarkers(): void { + throw new Error('Method not implemented.'); + } } export class MockRenderer implements IRenderer { diff --git a/src/common/buffer/Buffer.ts b/src/common/buffer/Buffer.ts index e348ad4cda..eed16609ff 100644 --- a/src/common/buffer/Buffer.ts +++ b/src/common/buffer/Buffer.ts @@ -16,7 +16,6 @@ import { DEFAULT_CHARSET } from 'common/data/Charsets'; import { ExtendedAttrs } from 'common/buffer/AttributeData'; export const MAX_BUFFER_SIZE = 4294967295; // 2^32 - 1 -const enum BufferState { CLEARING = 'clearing' } /** * This class represents a terminal buffer (an internal state of the terminal), where the @@ -44,7 +43,7 @@ export class Buffer implements IBuffer { private _whitespaceCell: ICellData = CellData.fromCharData([0, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_WIDTH, WHITESPACE_CELL_CODE]); private _cols: number; private _rows: number; - private _state: string | undefined; + private _isClearing: boolean = false; constructor( private _hasScrollback: boolean, @@ -587,12 +586,12 @@ export class Buffer implements IBuffer { } public clearMarkers(): void { - this._state = BufferState.CLEARING; + this._isClearing = true; for (const marker of this.markers) { marker.dispose(); } this.markers = []; - this._state = undefined; + this._isClearing = false; } public addMarker(y: number): Marker { @@ -626,7 +625,7 @@ export class Buffer implements IBuffer { } private _removeMarker(marker: Marker): void { - if (this._state !== BufferState.CLEARING) { + if (this._isClearing !== BufferState.CLEARING) { this.markers.splice(this.markers.indexOf(marker), 1); } } From ac7486856cf81ca2a8d8b23f5aa630544328afff Mon Sep 17 00:00:00 2001 From: meganrogge Date: Fri, 4 Feb 2022 17:41:54 -0600 Subject: [PATCH 4/7] improve conditional --- src/common/buffer/Buffer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/buffer/Buffer.ts b/src/common/buffer/Buffer.ts index eed16609ff..8addf45ada 100644 --- a/src/common/buffer/Buffer.ts +++ b/src/common/buffer/Buffer.ts @@ -625,7 +625,7 @@ export class Buffer implements IBuffer { } private _removeMarker(marker: Marker): void { - if (this._isClearing !== BufferState.CLEARING) { + if (!this._isClearing) { this.markers.splice(this.markers.indexOf(marker), 1); } } From 4d7d666c71feee9a95102f9c1e6252097af9d7ab Mon Sep 17 00:00:00 2001 From: meganrogge Date: Fri, 4 Feb 2022 18:00:13 -0600 Subject: [PATCH 5/7] add test --- src/browser/Terminal.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/browser/Terminal.test.ts b/src/browser/Terminal.test.ts index 872bfdc70b..0a0fd6ba04 100644 --- a/src/browser/Terminal.test.ts +++ b/src/browser/Terminal.test.ts @@ -80,6 +80,21 @@ describe('Terminal', () => { term.clear(); }); }); + it.only('should fire a scroll event when scrollback is cleared', () => { + return new Promise(async r => { + const marker1 = term.addMarker(0); + const marker2 = term.addMarker(1); + await term.writeP('\n'.repeat(INIT_ROWS)); + const marker3= term.addMarker(0); + const marker4 = term.addMarker(1); + marker1?.onDispose(() => r()); + marker2?.onDispose(() => r()); + marker3?.onDispose(() => r()); + marker4?.onDispose(() => r()); + term.clear(); + assert.equal(term.markers.length, 0); + }); + }); it('should fire a key event after a keypress DOM event', (done) => { term.onKey(e => { assert.equal(typeof e.key, 'string'); From 10adc87a3ed72cdb6c4141f6ffc19a4d01d313db Mon Sep 17 00:00:00 2001 From: meganrogge Date: Fri, 4 Feb 2022 19:32:34 -0600 Subject: [PATCH 6/7] add api test --- src/browser/Terminal.test.ts | 15 --------------- test/api/Terminal.api.ts | 25 ++++++++++++++++++++++++- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/browser/Terminal.test.ts b/src/browser/Terminal.test.ts index 0a0fd6ba04..872bfdc70b 100644 --- a/src/browser/Terminal.test.ts +++ b/src/browser/Terminal.test.ts @@ -80,21 +80,6 @@ describe('Terminal', () => { term.clear(); }); }); - it.only('should fire a scroll event when scrollback is cleared', () => { - return new Promise(async r => { - const marker1 = term.addMarker(0); - const marker2 = term.addMarker(1); - await term.writeP('\n'.repeat(INIT_ROWS)); - const marker3= term.addMarker(0); - const marker4 = term.addMarker(1); - marker1?.onDispose(() => r()); - marker2?.onDispose(() => r()); - marker3?.onDispose(() => r()); - marker4?.onDispose(() => r()); - term.clear(); - assert.equal(term.markers.length, 0); - }); - }); it('should fire a key event after a keypress DOM event', (done) => { term.onKey(e => { assert.equal(typeof e.key, 'string'); diff --git a/test/api/Terminal.api.ts b/test/api/Terminal.api.ts index 2b0c00d470..b39ffd6f8a 100644 --- a/test/api/Terminal.api.ts +++ b/test/api/Terminal.api.ts @@ -15,7 +15,7 @@ let page: Page; const width = 800; const height = 600; -describe('API Integration Tests', function(): void { +describe.only('API Integration Tests', function(): void { before(async () => { browser = await launchBrowser(); page = await (await browser.newContext()).newPage(); @@ -559,6 +559,29 @@ describe('API Integration Tests', function(): void { assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).getCell(2).getChars()`), ''); assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).getCell(2).getWidth()`), 0); }); + + it('clearMarkers', async () => { + await openTerminal(page, { cols: 5 }); + await page.evaluate(` + window.disposeStack = []; + `); + await writeSync(page, '\\n\\n\\n\\n'); + await writeSync(page, '\\n\\n\\n\\n'); + await writeSync(page, '\\n\\n\\n\\n'); + await writeSync(page, '\\n\\n\\n\\n'); + await page.evaluate(`window.term.addMarker(1)`); + await page.evaluate(`window.term.addMarker(2)`); + await page.evaluate(`window.term.scrollLines(10)`); + await page.evaluate(`window.term.addMarker(3)`); + await page.evaluate(`window.term.addMarker(4)`); + await page.evaluate(` + for (let i = 0; i < window.term.markers.length; ++i) { + const marker = window.term.markers[i]; + marker.onDispose(() => window.disposeStack.push(marker)); + }`); + await page.evaluate(`window.term.clear()`); + assert.equal(await page.evaluate(`window.disposeStack.length`), 4); + }); }); it('active, normal, alternate', async () => { From 494aef1c94f0c8ed7b1c48f5684f0fb3f650bcf7 Mon Sep 17 00:00:00 2001 From: meganrogge Date: Fri, 4 Feb 2022 19:59:10 -0600 Subject: [PATCH 7/7] remove .only --- test/api/Terminal.api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/api/Terminal.api.ts b/test/api/Terminal.api.ts index b39ffd6f8a..1fe7545680 100644 --- a/test/api/Terminal.api.ts +++ b/test/api/Terminal.api.ts @@ -15,7 +15,7 @@ let page: Page; const width = 800; const height = 600; -describe.only('API Integration Tests', function(): void { +describe('API Integration Tests', function(): void { before(async () => { browser = await launchBrowser(); page = await (await browser.newContext()).newPage();