Skip to content

Commit

Permalink
Fix tests and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Jul 16, 2017
1 parent 341a34d commit 6d4bcbe
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
15 changes: 8 additions & 7 deletions src/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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]);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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-
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions src/addons/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/BufferLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6d4bcbe

Please sign in to comment.