From 6d4bcbe8b8d2464617103e988628a53398adbfd9 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 15 Jul 2017 21:30:12 -0700 Subject: [PATCH] Fix tests and lint --- src/InputHandler.ts | 15 ++++++++------- src/Renderer.ts | 5 +++-- src/addons/search/search.ts | 4 ++-- src/test/test.js | 4 ++-- src/utils/BufferLine.ts | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 02a01464b1..ef4d7c1560 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -6,6 +6,7 @@ import { IInputHandler, ITerminal } from './Interfaces'; import { C0 } from './EscapeSequences'; import { DEFAULT_CHARSET } from './Charsets'; import { CharAttributes } from './CharAttributes'; +import { CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX } from './utils/BufferLine'; /** * The terminal's standard implementation of IInputHandler, this handles all @@ -35,14 +36,14 @@ export class InputHandler implements IInputHandler { if (!ch_width && this._terminal.buffer.x) { // dont overflow left if (this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1]) { - if (!this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1][2]) { + if (!this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1][CHAR_DATA_WIDTH_INDEX]) { // found empty cell after fullwidth, need to go 2 cells back if (this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 2]) - this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 2][1] += char; + this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 2][CHAR_DATA_CHAR_INDEX] += char; } else { - this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1][1] += char; + this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1][CHAR_DATA_CHAR_INDEX] += char; } this._terminal.updateRange(this._terminal.buffer.y); } @@ -78,14 +79,14 @@ export class InputHandler implements IInputHandler { // remove last cell, if it's width is 0 // we have to adjust the second last cell as well const removed = this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase).pop(); - if (removed[2] === 0 + if (removed[CHAR_DATA_WIDTH_INDEX] === 0 && this._terminal.buffer.lines.get(row)[this._terminal.cols - 2] - && this._terminal.buffer.lines.get(row)[this._terminal.cols - 2][2] === 2) { + && this._terminal.buffer.lines.get(row)[this._terminal.cols - 2][CHAR_DATA_WIDTH_INDEX] === 2) { this._terminal.buffer.lines.get(row)[this._terminal.cols - 2] = [' ', 1, this._terminal.currentFlags, this._terminal.currentFgColor, this._terminal.currentBgColor]; } // insert empty cell at cursor - this._terminal.buffer.lines.get(row).splice(this._terminal.x, 0, [' ', 1, this._terminal.currentFlags, this._terminal.currentFgColor, this._terminal.currentBgColor]); + this._terminal.buffer.lines.get(row).splice(this._terminal.buffer.x, 0, [' ', 1, this._terminal.currentFlags, this._terminal.currentFgColor, this._terminal.currentBgColor]); } } @@ -1303,7 +1304,7 @@ export class InputHandler implements IInputHandler { } this._terminal.finalizeCharAttributes(); - this._terminal.currentCharAttributes = new CharAttributes(this._terminal.x, this._terminal.ybase + this._terminal.y, null, null, [this._terminal.currentFlags, this._terminal.currentFgColor, this._terminal.currentBgColor]); + this._terminal.currentCharAttributes = new CharAttributes(this._terminal.buffer.x, this._terminal.buffer.ybase + this._terminal.buffer.y, null, null, [this._terminal.currentFlags, this._terminal.currentFgColor, this._terminal.currentBgColor]); this._terminal.charAttributes.push(this._terminal.currentCharAttributes); console.log('Creating new style attr:', this._terminal.currentCharAttributes); } diff --git a/src/Renderer.ts b/src/Renderer.ts index 75ea6c1e01..c6a145b2c6 100644 --- a/src/Renderer.ts +++ b/src/Renderer.ts @@ -5,6 +5,7 @@ import { ITerminal } from './Interfaces'; import { DomElementObjectPool } from './utils/DomElementObjectPool'; import { CharAttributes } from './CharAttributes'; +import { CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX } from './utils/BufferLine'; /** * The maximum number of refresh frames to skip when the write buffer is non- @@ -164,8 +165,8 @@ export class Renderer { // Process each character in the line for (let i = 0; i < width; i++) { - const ch: string = line[i][0]; - const ch_width: number = line[i][1]; + const ch: string = line[i][CHAR_DATA_CHAR_INDEX]; + const ch_width: number = line[i][CHAR_DATA_WIDTH_INDEX]; let flags: number = line[i][2]; let fg: number = line[i][3]; let bg: number = line[i][4]; diff --git a/src/addons/search/search.ts b/src/addons/search/search.ts index 5a227a8a15..4d34f155e3 100644 --- a/src/addons/search/search.ts +++ b/src/addons/search/search.ts @@ -11,7 +11,7 @@ declare var require: any; declare var window: any; (function (addon) { - if ('Terminal' in window) { + if (typeof window !== 'undefined' && 'Terminal' in window) { /** * Plain browser environment */ @@ -22,7 +22,7 @@ declare var window: any; */ const xterm = '../../xterm'; module.exports = addon(require(xterm)); - } else if (typeof define == 'function') { + } else if (typeof define === 'function') { /** * Require.js is available */ diff --git a/src/test/test.js b/src/test/test.js index 1ba7bf223d..dbf34b0aee 100644 --- a/src/test/test.js +++ b/src/test/test.js @@ -588,8 +588,8 @@ describe('xterm.js', function() { for (var i=0xDC00; i<=0xDCFF; ++i) { xterm.buffer.x = xterm.cols - 1; xterm.write(high + String.fromCharCode(i)); - expect(xterm.buffer.lines.get(0)[xterm.x-1][0]).eql(high + String.fromCharCode(i)); - expect(xterm.buffer.lines.get(0)[xterm.x-1][0].length).eql(2); + expect(xterm.buffer.lines.get(0)[xterm.buffer.x-1][0]).eql(high + String.fromCharCode(i)); + expect(xterm.buffer.lines.get(0)[xterm.buffer.x-1][0].length).eql(2); expect(xterm.buffer.lines.get(1)[0][0]).eql(' '); xterm.reset(); } diff --git a/src/utils/BufferLine.ts b/src/utils/BufferLine.ts index e6f50ac367..82482886e7 100644 --- a/src/utils/BufferLine.ts +++ b/src/utils/BufferLine.ts @@ -4,7 +4,7 @@ // TODO: This module should be merged into a buffer or buffer line class -import { CharData } from "../Types"; +import { CharData } from '../Types'; export const CHAR_DATA_CHAR_INDEX = 0; export const CHAR_DATA_WIDTH_INDEX = 1;