From 607c8191095da14bde0c60c8dae838e1e6d87156 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sun, 27 Nov 2016 03:27:36 -0800 Subject: [PATCH] Progress --- src/test/escape-sequences-test.js | 10 ++- src/test/test.js | 140 +++++++++++++++--------------- src/utils/CircularList.ts | 5 ++ src/xterm.js | 65 +++++++------- 4 files changed, 115 insertions(+), 105 deletions(-) diff --git a/src/test/escape-sequences-test.js b/src/test/escape-sequences-test.js index 2eb60165..05fb75fb 100644 --- a/src/test/escape-sequences-test.js +++ b/src/test/escape-sequences-test.js @@ -59,7 +59,7 @@ function terminalToString(term) { for (var line=0; line { return this._array[this._getCyclicIndex(this._length-- - 1)]; } + public removeItemsFromStart(amount: number): void { + this._startIndex += this._length -amount; + this._length = amount; + } + // TODO: Warn there's no error handling and that this is a slow operation public splice(start: number, deleteCount: number, ...items: T[]) { if (deleteCount) { diff --git a/src/xterm.js b/src/xterm.js index c88423d4..72394147 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -35,6 +35,7 @@ import { CompositionHelper } from './CompositionHelper.js'; import { EventEmitter } from './EventEmitter.js'; import { Viewport } from './Viewport.js'; import { rightClickHandler, pasteHandler, copyHandler } from './handlers/Clipboard.js'; +import { CircularList } from './utils/CircularList.js'; import * as Browser from './utils/Browser'; import * as Keyboard from './utils/Keyboard'; @@ -229,7 +230,7 @@ function Terminal(options) { * An array of all lines in the entire buffer, including the prompt. The lines are array of * characters which are 2-length arrays where [0] is an attribute and [1] is the character. */ - this.lines = []; + this.lines = new CircularList(this.scrollback); var i = this.rows; while (i--) { this.lines.push(this.blankLine()); @@ -1096,7 +1097,7 @@ Terminal.prototype.refresh = function(start, end, queue) { for (; y <= end; y++) { row = y + this.ydisp; - line = this.lines[row]; + line = this.lines.get(row); out = ''; if (this.y === y - (this.ybase - this.ydisp) @@ -1252,8 +1253,9 @@ Terminal.prototype.scroll = function() { var row; if (++this.ybase === this.scrollback) { - this.ybase = this.ybase / 2 | 0; - this.lines = this.lines.slice(-(this.ybase + this.rows) + 1); + this.ybase = this.ybase / 2; + // TODO: Rely on the circular list instead of cutting it in half + this.lines.removeItemsFromStart(this.ybase + this.rows - 1); } if (!this.userScrolling) { @@ -1388,7 +1390,6 @@ Terminal.prototype.write = function(data) { // surrogate low - already handled above if (0xDC00 <= code && code <= 0xDFFF) continue; - switch (this.state) { case normal: switch (ch) { @@ -1458,17 +1459,16 @@ Terminal.prototype.write = function(data) { // insert combining char in last cell // FIXME: needs handling after cursor jumps if (!ch_width && this.x) { - // dont overflow left - if (this.lines[row][this.x-1]) { - if (!this.lines[row][this.x-1][2]) { + if (this.lines.get(row)[this.x-1]) { + if (!this.lines.get(row)[this.x-1][2]) { // found empty cell after fullwidth, need to go 2 cells back - if (this.lines[row][this.x-2]) - this.lines[row][this.x-2][1] += ch; + if (this.lines.get(row)[this.x-2]) + this.lines.get(row)[this.x-2][1] += ch; } else { - this.lines[row][this.x-1][1] += ch; + this.lines.get(row)[this.x-1][1] += ch; } this.updateRange(this.y); } @@ -1500,24 +1500,24 @@ Terminal.prototype.write = function(data) { for (var moves=0; moves x) i = this.lines.length; while (i--) { - while (this.lines[i].length > x) { - this.lines[i].pop(); + while (this.lines.get(i).length > x) { + this.lines.get(i).pop(); } } } @@ -3044,7 +3044,7 @@ Terminal.prototype.nextStop = function(x) { * @param {number} y The line in which to operate. */ Terminal.prototype.eraseRight = function(x, y) { - var line = this.lines[this.ybase + y] + var line = this.lines.get(this.ybase + y) , ch = [this.eraseAttr(), ' ', 1]; // xterm @@ -3063,7 +3063,7 @@ Terminal.prototype.eraseRight = function(x, y) { * @param {number} y The line in which to operate. */ Terminal.prototype.eraseLeft = function(x, y) { - var line = this.lines[this.ybase + y] + var line = this.lines.get(this.ybase + y) , ch = [this.eraseAttr(), ' ', 1]; // xterm x++; @@ -3080,7 +3080,8 @@ Terminal.prototype.clear = function() { // Don't clear if it's already clear return; } - this.lines = [this.lines[this.ybase + this.y]]; + this.lines.set(0, this.lines.get(this.ybase + this.y)); + this.lines.length = 1; this.ydisp = 0; this.ybase = 0; this.y = 0; @@ -3655,8 +3656,8 @@ Terminal.prototype.insertChars = function(params) { ch = [this.eraseAttr(), ' ', 1]; // xterm while (param-- && j < this.cols) { - this.lines[row].splice(j++, 0, ch); - this.lines[row].pop(); + this.lines.get(row).splice(j++, 0, ch); + this.lines.get(row).pop(); } }; @@ -3789,7 +3790,7 @@ Terminal.prototype.eraseChars = function(params) { ch = [this.eraseAttr(), ' ', 1]; // xterm while (param-- && j < this.cols) { - this.lines[row][j++] = ch; + this.lines.get(row)[j++] = ch; } }; @@ -4453,7 +4454,7 @@ Terminal.prototype.cursorBackwardTab = function(params) { */ Terminal.prototype.repeatPrecedingCharacter = function(params) { var param = params[0] || 1 - , line = this.lines[this.ybase + this.y] + , line = this.lines.get(this.ybase + this.y) , ch = line[this.x - 1] || [this.defAttr, ' ', 1]; while (param--) line[this.x++] = ch; @@ -4688,7 +4689,7 @@ Terminal.prototype.setAttrInRectangle = function(params) { , i; for (; t < b + 1; t++) { - line = this.lines[this.ybase + t]; + line = this.lines.get(this.ybase + t); for (i = l; i < r; i++) { line[i] = [attr, line[i][1]]; } @@ -4718,7 +4719,7 @@ Terminal.prototype.fillRectangle = function(params) { , i; for (; t < b + 1; t++) { - line = this.lines[this.ybase + t]; + line = this.lines.get(this.ybase + t); for (i = l; i < r; i++) { line[i] = [line[i][0], String.fromCharCode(ch)]; } @@ -4770,7 +4771,7 @@ Terminal.prototype.eraseRectangle = function(params) { ch = [this.eraseAttr(), ' ', 1]; // xterm? for (; t < b + 1; t++) { - line = this.lines[this.ybase + t]; + line = this.lines.get(this.ybase + t); for (i = l; i < r; i++) { line[i] = ch; }