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/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', () => { diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 089c2d0d..bd9ea0c9 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -1833,6 +1833,7 @@ export class InputHandler extends Disposable 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; } @@ -1844,6 +1845,7 @@ export class InputHandler extends Disposable 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 || DEFAULT_ATTR; } 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', () => { diff --git a/src/Terminal.test.ts b/src/Terminal.test.ts index 0745ddda..0ea854e2 100644 --- a/src/Terminal.test.ts +++ b/src/Terminal.test.ts @@ -120,6 +120,17 @@ describe('term.js addons', () => { }); }); + describe('reset', () => { + it('should not affect cursorState', () => { + term.cursorState = 1; + term.reset(); + assert.equal(term.cursorState, 1); + term.cursorState = 0; + term.reset(); + assert.equal(term.cursorState, 0); + }); + }); + describe('clear', () => { it('should clear a buffer equal to rows', () => { const promptLine = term.buffer.lines.get(term.buffer.ybase + term.buffer.y); diff --git a/src/Terminal.ts b/src/Terminal.ts index 7dd5117a..971c0fc9 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -171,6 +171,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; @@ -441,6 +442,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II this.charMeasure.measure(this.options); } break; + case 'drawBoldTextInBrightColors': case 'experimentalCharAtlas': case 'enableBold': case 'letterSpacing': @@ -1835,9 +1837,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(); diff --git a/src/renderer/dom/DomRenderer.ts b/src/renderer/dom/DomRenderer.ts index 12932a5e..989e147d 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; } diff --git a/src/utils/TestUtils.test.ts b/src/utils/TestUtils.test.ts index ebb56ee2..59b55cf3 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;