From 6c3b6b46557001e5cb89c517faeba51967997a91 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 12 Jun 2018 17:54:26 +0200 Subject: [PATCH 01/12] Ensure drawBoldTextInBrightColors redraws screen --- src/Terminal.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Terminal.ts b/src/Terminal.ts index 8a71df96..1f979528 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -474,6 +474,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II this.charMeasure.measure(this.options); } break; + case 'drawBoldTextInBrightColors': case 'experimentalCharAtlas': case 'enableBold': case 'letterSpacing': From 8dcb4698d364557e9333d2f4d410d5c2b6e0e877 Mon Sep 17 00:00:00 2001 From: Benjamin Raymond Date: Wed, 20 Jun 2018 13:57:42 +0200 Subject: [PATCH 02/12] #1521: now saving and restoring characters attributes when using ANSI escape sequences 'ESC 7' (DECSC) and 'ESC 8' (DECRC) --- src/InputHandler.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/InputHandler.ts b/src/InputHandler.ts index dbf6dfb2..f35ab522 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -1822,6 +1822,7 @@ export class InputHandler implements IInputHandler { public saveCursor(params: number[]): void { this._terminal.buffer.savedX = this._terminal.buffer.x; this._terminal.buffer.savedY = this._terminal.buffer.y; + this._terminal.savedCurAttr = this._terminal.curAttr; } @@ -1833,6 +1834,7 @@ export class InputHandler implements IInputHandler { public restoreCursor(params: number[]): void { this._terminal.buffer.x = this._terminal.buffer.savedX || 0; this._terminal.buffer.y = this._terminal.buffer.savedY || 0; + this._terminal.curAttr = this._terminal.savedCurAttr; } From c345dba591956ce10bc9f1b6661b6cf91c6ce1b8 Mon Sep 17 00:00:00 2001 From: Benjamin Raymond Date: Wed, 20 Jun 2018 13:58:53 +0200 Subject: [PATCH 03/12] #1521: added 'savedCurAttr' property in 'Terminal' class which holds the saved state of the character attributes ('ESC 7' escape sequence code) --- src/Terminal.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Terminal.ts b/src/Terminal.ts index 8a71df96..970423fe 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -198,6 +198,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II public savedCols: number; public curAttr: number; + public savedCurAttr: number; public params: (string | number)[]; public currentParam: string | number; From a1b8f96d50d7dcccc2cbe4c0392dc263f7e9ecd5 Mon Sep 17 00:00:00 2001 From: Benjamin Raymond Date: Wed, 20 Jun 2018 14:04:13 +0200 Subject: [PATCH 04/12] #1521: added default behavior of 'ESC 8' escape sequence (DECRC) when cursor state was never saved before using 'ESC 7' (DECSC) --- src/InputHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/InputHandler.ts b/src/InputHandler.ts index f35ab522..72b3614c 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -1834,7 +1834,7 @@ export class InputHandler implements IInputHandler { public restoreCursor(params: number[]): void { this._terminal.buffer.x = this._terminal.buffer.savedX || 0; this._terminal.buffer.y = this._terminal.buffer.savedY || 0; - this._terminal.curAttr = this._terminal.savedCurAttr; + this._terminal.curAttr = this._terminal.savedCurAttr || 0; } From 285b0b6702f1b9164c18708d897514ccb4585d16 Mon Sep 17 00:00:00 2001 From: 7PH Date: Wed, 20 Jun 2018 14:23:05 +0200 Subject: [PATCH 05/12] #1521: added 'savedCurAttr' attribute to 'MockInputHandlingTerminal' class --- src/utils/TestUtils.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/TestUtils.test.ts b/src/utils/TestUtils.test.ts index f4bad717..763eb3e6 100644 --- a/src/utils/TestUtils.test.ts +++ b/src/utils/TestUtils.test.ts @@ -182,6 +182,7 @@ export class MockInputHandlingTerminal implements IInputHandlingTerminal { wraparoundMode: boolean; bracketedPasteMode: boolean; curAttr: number; + savedCurAttr: number; savedCols: number; x10Mouse: boolean; vt200Mouse: boolean; From 4fecf05dabcfeb99f02c5b86c352b12f899ad194 Mon Sep 17 00:00:00 2001 From: 7PH Date: Wed, 20 Jun 2018 14:31:12 +0200 Subject: [PATCH 06/12] #1521: added unit tests for saving & restoring cursor attributes --- src/InputHandler.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/InputHandler.test.ts b/src/InputHandler.test.ts index 6dc043db..e8099914 100644 --- a/src/InputHandler.test.ts +++ b/src/InputHandler.test.ts @@ -12,18 +12,22 @@ describe('InputHandler', () => { const terminal = new MockInputHandlingTerminal(); terminal.buffer.x = 1; terminal.buffer.y = 2; + terminal.curAttr = 3; const inputHandler = new InputHandler(terminal); // Save cursor position inputHandler.saveCursor([]); assert.equal(terminal.buffer.x, 1); assert.equal(terminal.buffer.y, 2); + assert.equal(terminal.curAttr, 3); // Change cursor position terminal.buffer.x = 10; terminal.buffer.y = 20; + terminal.curAttr = 30; // Restore cursor position inputHandler.restoreCursor([]); assert.equal(terminal.buffer.x, 1); assert.equal(terminal.buffer.y, 2); + assert.equal(terminal.curAttr, 3); }); describe('setCursorStyle', () => { it('should call Terminal.setOption with correct params', () => { From 086b2c04e082d42683277a94b57969ebd281c31c Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Wed, 20 Jun 2018 23:02:05 +1000 Subject: [PATCH 07/12] Make sure DOM renderer doesn't render cells beyond cols Fixes #1523 --- src/renderer/dom/DomRenderer.ts | 2 +- .../dom/DomRendererRowFactory.test.ts | 31 ++++++++++++------- src/renderer/dom/DomRendererRowFactory.ts | 10 +++++- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/renderer/dom/DomRenderer.ts b/src/renderer/dom/DomRenderer.ts index 5b1813b5..8c335dca 100644 --- a/src/renderer/dom/DomRenderer.ts +++ b/src/renderer/dom/DomRenderer.ts @@ -303,7 +303,7 @@ export class DomRenderer extends EventEmitter implements IRenderer { const row = y + terminal.buffer.ydisp; const lineData = terminal.buffer.lines.get(row); - rowElement.appendChild(this._rowFactory.createRow(lineData, row === cursorAbsoluteY, cursorX, terminal.charMeasure.width)); + rowElement.appendChild(this._rowFactory.createRow(lineData, row === cursorAbsoluteY, cursorX, terminal.charMeasure.width, terminal.cols)); } this._terminal.emit('refresh', {start, end}); diff --git a/src/renderer/dom/DomRendererRowFactory.test.ts b/src/renderer/dom/DomRendererRowFactory.test.ts index f28830ce..e91c71fe 100644 --- a/src/renderer/dom/DomRendererRowFactory.test.ts +++ b/src/renderer/dom/DomRendererRowFactory.test.ts @@ -23,7 +23,7 @@ describe('DomRendererRowFactory', () => { describe('createRow', () => { it('should create an element for every character in the row', () => { - const fragment = rowFactory.createRow(lineData, false, 0, 5); + const fragment = rowFactory.createRow(lineData, false, 0, 5, 20); assert.equal(getFragmentHtml(fragment), ' ' + ' ' @@ -34,24 +34,33 @@ describe('DomRendererRowFactory', () => { lineData[0] = [DEFAULT_ATTR, '語', 2, '語'.charCodeAt(0)]; // There should be no element for the following "empty" cell lineData[1] = [DEFAULT_ATTR, '', 0, undefined]; - const fragment = rowFactory.createRow(lineData, false, 0, 5); + const fragment = rowFactory.createRow(lineData, false, 0, 5, 20); assert.equal(getFragmentHtml(fragment), '' ); }); it('should add class for cursor', () => { - const fragment = rowFactory.createRow(lineData, true, 0, 5); + const fragment = rowFactory.createRow(lineData, true, 0, 5, 20); assert.equal(getFragmentHtml(fragment), ' ' + ' ' ); }); + it('should not render cells that go beyond the terminal\'s columns', () => { + lineData[0] = [DEFAULT_ATTR, 'a', 1, 'a'.charCodeAt(0)]; + lineData[1] = [DEFAULT_ATTR, 'b', 1, 'b'.charCodeAt(0)]; + const fragment = rowFactory.createRow(lineData, false, 0, 5, 1); + assert.equal(getFragmentHtml(fragment), + 'a' + ); + }); + describe('attributes', () => { it('should add class for bold', () => { lineData[0] = [DEFAULT_ATTR | (FLAGS.BOLD << 18), 'a', 1, 'a'.charCodeAt(0)]; - const fragment = rowFactory.createRow(lineData, false, 0, 5); + const fragment = rowFactory.createRow(lineData, false, 0, 5, 20); assert.equal(getFragmentHtml(fragment), 'a' + ' ' @@ -60,7 +69,7 @@ describe('DomRendererRowFactory', () => { it('should add class for italic', () => { lineData[0] = [DEFAULT_ATTR | (FLAGS.ITALIC << 18), 'a', 1, 'a'.charCodeAt(0)]; - const fragment = rowFactory.createRow(lineData, false, 0, 5); + const fragment = rowFactory.createRow(lineData, false, 0, 5, 20); assert.equal(getFragmentHtml(fragment), 'a' + ' ' @@ -71,7 +80,7 @@ describe('DomRendererRowFactory', () => { const defaultAttrNoFgColor = (0 << 9) | (256 << 0); for (let i = 0; i < 256; i++) { lineData[0] = [defaultAttrNoFgColor | (i << 9), 'a', 1, 'a'.charCodeAt(0)]; - const fragment = rowFactory.createRow(lineData, false, 0, 5); + const fragment = rowFactory.createRow(lineData, false, 0, 5, 20); assert.equal(getFragmentHtml(fragment), `a` + ' ' @@ -83,7 +92,7 @@ describe('DomRendererRowFactory', () => { const defaultAttrNoBgColor = (257 << 9) | (0 << 0); for (let i = 0; i < 256; i++) { lineData[0] = [defaultAttrNoBgColor | (i << 0), 'a', 1, 'a'.charCodeAt(0)]; - const fragment = rowFactory.createRow(lineData, false, 0, 5); + const fragment = rowFactory.createRow(lineData, false, 0, 5, 20); assert.equal(getFragmentHtml(fragment), `a` + ' ' @@ -93,7 +102,7 @@ describe('DomRendererRowFactory', () => { it('should correctly invert colors', () => { lineData[0] = [(FLAGS.INVERSE << 18) | (2 << 9) | (1 << 0), 'a', 1, 'a'.charCodeAt(0)]; - const fragment = rowFactory.createRow(lineData, false, 0, 5); + const fragment = rowFactory.createRow(lineData, false, 0, 5, 20); assert.equal(getFragmentHtml(fragment), 'a' + ' ' @@ -102,7 +111,7 @@ describe('DomRendererRowFactory', () => { it('should correctly invert default fg color', () => { lineData[0] = [(FLAGS.INVERSE << 18) | (257 << 9) | (1 << 0), 'a', 1, 'a'.charCodeAt(0)]; - const fragment = rowFactory.createRow(lineData, false, 0, 5); + const fragment = rowFactory.createRow(lineData, false, 0, 5, 20); assert.equal(getFragmentHtml(fragment), 'a' + ' ' @@ -111,7 +120,7 @@ describe('DomRendererRowFactory', () => { it('should correctly invert default bg color', () => { lineData[0] = [(FLAGS.INVERSE << 18) | (1 << 9) | (256 << 0), 'a', 1, 'a'.charCodeAt(0)]; - const fragment = rowFactory.createRow(lineData, false, 0, 5); + const fragment = rowFactory.createRow(lineData, false, 0, 5, 20); assert.equal(getFragmentHtml(fragment), 'a' + ' ' @@ -121,7 +130,7 @@ describe('DomRendererRowFactory', () => { it('should turn bold fg text bright', () => { for (let i = 0; i < 8; i++) { lineData[0] = [(FLAGS.BOLD << 18) | (i << 9) | (256 << 0), 'a', 1, 'a'.charCodeAt(0)]; - const fragment = rowFactory.createRow(lineData, false, 0, 5); + const fragment = rowFactory.createRow(lineData, false, 0, 5, 20); assert.equal(getFragmentHtml(fragment), `a` + ' ' diff --git a/src/renderer/dom/DomRendererRowFactory.ts b/src/renderer/dom/DomRendererRowFactory.ts index d72629a3..eedb1d34 100644 --- a/src/renderer/dom/DomRendererRowFactory.ts +++ b/src/renderer/dom/DomRendererRowFactory.ts @@ -17,9 +17,16 @@ export class DomRendererRowFactory { ) { } - public createRow(lineData: LineData, isCursorRow: boolean, cursorX: number, cellWidth: number): DocumentFragment { + public createRow(lineData: LineData, isCursorRow: boolean, cursorX: number, cellWidth: number, cols: number): DocumentFragment { const fragment = this._document.createDocumentFragment(); + let colCount = 0; + for (let x = 0; x < lineData.length; x++) { + // Don't allow any buffer to the right to be displayed + if (colCount >= cols) { + continue; + } + const charData = lineData[x]; const char: string = charData[CHAR_DATA_CHAR_INDEX]; const attr: number = charData[CHAR_DATA_ATTR_INDEX]; @@ -76,6 +83,7 @@ export class DomRendererRowFactory { charElement.classList.add(`xterm-bg-${bg}`); } fragment.appendChild(charElement); + colCount += width; } return fragment; } From 43ffa957ab32f156863fae0abea9573ff0aee70b Mon Sep 17 00:00:00 2001 From: 7PH Date: Thu, 21 Jun 2018 09:22:17 +0200 Subject: [PATCH 08/12] #1521: fixed default value of 'Terminal.curAttr' when restoring a not previously saved cursor state --- src/InputHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 72b3614c..e83cff40 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -1834,7 +1834,7 @@ export class InputHandler implements IInputHandler { public restoreCursor(params: number[]): void { this._terminal.buffer.x = this._terminal.buffer.savedX || 0; this._terminal.buffer.y = this._terminal.buffer.savedY || 0; - this._terminal.curAttr = this._terminal.savedCurAttr || 0; + this._terminal.curAttr = this._terminal.savedCurAttr || DEFAULT_ATTR; } From ff18b193eb2cf8615488d503b4ef148c69f64e7b Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 25 Jun 2018 11:27:57 -0700 Subject: [PATCH 09/12] Pin node-pty to 0.7.6 --- package.json | 2 +- src/Terminal.integration.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4aaac342..2887d56a 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "jsdoc": "3.4.3", "jsdom": "^11.11.0", "merge-stream": "^1.0.1", - "node-pty": "^0.7.2", + "node-pty": "0.7.6", "nodemon": "1.10.2", "npm-run-all": "^4.1.2", "nyc": "^11.8.0", diff --git a/src/Terminal.integration.ts b/src/Terminal.integration.ts index 7b7cdbdd..f37d7840 100644 --- a/src/Terminal.integration.ts +++ b/src/Terminal.integration.ts @@ -88,7 +88,7 @@ if (os.platform() !== 'win32') { /** some helpers for pty interaction */ // we need a pty in between to get the termios decorations // for the basic test cases a raw pty device is enough - primitivePty = pty.native.open(cols, rows); + primitivePty = (pty).native.open(cols, rows); /** tests */ describe('xterm output comparison', () => { From f1504e5c0fd8297a9f5e3773ee6b87444fb45c2b Mon Sep 17 00:00:00 2001 From: 7PH Date: Tue, 26 Jun 2018 10:33:46 +0200 Subject: [PATCH 10/12] #1532: Terminal reset does not affect cursorState anymore --- src/Terminal.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Terminal.ts b/src/Terminal.ts index 4d062f76..9f581461 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -1830,9 +1830,11 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II this.options.cols = this.cols; const customKeyEventHandler = this._customKeyEventHandler; const inputHandler = this._inputHandler; + const cursorState = this.cursorState; this._setup(); this._customKeyEventHandler = customKeyEventHandler; this._inputHandler = inputHandler; + this.cursorState = cursorState; this.refresh(0, this.rows - 1); if (this.viewport) { this.viewport.syncScrollArea(); From 0ad7b8e27b2da454991ad6fd0d5a3c27c870f67e Mon Sep 17 00:00:00 2001 From: 7PH Date: Tue, 26 Jun 2018 10:36:11 +0200 Subject: [PATCH 11/12] #1532: Add test to ensure terminal reset does not affect cursorState --- src/Terminal.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Terminal.test.ts b/src/Terminal.test.ts index 0745ddda..28ce6ce8 100644 --- a/src/Terminal.test.ts +++ b/src/Terminal.test.ts @@ -120,6 +120,14 @@ describe('term.js addons', () => { }); }); + describe('reset', () => { + it('should not affect cursorState', () => { + term.cursorState = 1; + term.reset(); + assert.equal(term.cursorState, 1); + }); + }); + describe('clear', () => { it('should clear a buffer equal to rows', () => { const promptLine = term.buffer.lines.get(term.buffer.ybase + term.buffer.y); From 218a4014c78b64ec6b681ca1964e0235c86e67c2 Mon Sep 17 00:00:00 2001 From: 7PH Date: Tue, 26 Jun 2018 10:42:08 +0200 Subject: [PATCH 12/12] #1532: Add test to ensure terminal reset does not display cursor if hidden before --- src/Terminal.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Terminal.test.ts b/src/Terminal.test.ts index 28ce6ce8..0ea854e2 100644 --- a/src/Terminal.test.ts +++ b/src/Terminal.test.ts @@ -125,6 +125,9 @@ describe('term.js addons', () => { term.cursorState = 1; term.reset(); assert.equal(term.cursorState, 1); + term.cursorState = 0; + term.reset(); + assert.equal(term.cursorState, 0); }); });