]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Progress
authorDaniel Imms <daimms@microsoft.com>
Sun, 27 Nov 2016 11:27:36 +0000 (03:27 -0800)
committerDaniel Imms <daimms@microsoft.com>
Sun, 27 Nov 2016 11:27:36 +0000 (03:27 -0800)
src/test/escape-sequences-test.js
src/test/test.js
src/utils/CircularList.ts
src/xterm.js

index 2eb60165562330397bdc51f72f9a3fbcefa06555..05fb75fb55cb90862f8aad894d2df7a3a5b9ff4b 100644 (file)
@@ -59,7 +59,7 @@ function terminalToString(term) {
   for (var line=0; line<term.rows; ++line) {
     line_s = '';
     for (var cell=0; cell<term.cols; ++cell) {
-      line_s += term.lines[line][cell][1];
+      line_s += term.lines.get(line)[cell][1];
     }
     // rtrim empty cells as xterm does
     line_s = line_s.replace(/\s+$/, '');
@@ -83,21 +83,25 @@ describe('xterm output comparison', function() {
   var files = glob.sync('**/escape_sequence_files/*.in');
   // only successful tests for now
   var successful = [0, 2, 6, 12, 13, 18, 20, 22, 27, 28];
-  console.log(files);
   for (var a in successful) {
     var i = successful[a];
     (function(filename){
       it(filename.split('/').slice(-1)[0], function () {
+        console.log(filename);
         pty_reset();
+        console.log(1);
         var in_file = fs.readFileSync(filename, 'utf8');
         var from_pty = pty_write_read(in_file);
+        console.log(2);
         // uncomment this to get log from terminal
-        console.log = function(){};
+        //console.log = function(){};
         xterm.write(from_pty);
         var from_emulator = terminalToString(xterm);
+        console.log(3);
         console.log = CONSOLE_LOG;
         var expected = fs.readFileSync(filename.split('.')[0] + '.text', 'utf8');
         if (from_emulator != expected) {
+        console.log(4);
           // uncomment to get noisy output
           //throw new Error(formatError(in_file, from_emulator, expected));
           throw new Error('mismatch');
index abdc8c176e9c7c09792d7ec6326affeb93cdd216..87403cf7777c90a2c877dfc0ef611ff0778911f0 100644 (file)
@@ -48,15 +48,15 @@ describe('xterm.js', function() {
 
   describe('clear', function() {
     it('should clear a buffer equal to rows', function() {
-      var promptLine = xterm.lines[xterm.ybase + xterm.y];
+      var promptLine = xterm.lines.get(xterm.ybase + xterm.y);
       xterm.clear();
       assert.equal(xterm.y, 0);
       assert.equal(xterm.ybase, 0);
       assert.equal(xterm.ydisp, 0);
       assert.equal(xterm.lines.length, xterm.rows);
-      assert.deepEqual(xterm.lines[0], promptLine);
+      assert.deepEqual(xterm.lines.get(0), promptLine);
       for (var i = 1; i < xterm.rows; i++) {
-        assert.deepEqual(xterm.lines[0], xterm.blankLine());
+        assert.deepEqual(xterm.lines.get(i), xterm.blankLine());
       }
     });
     it('should clear a buffer larger than rows', function() {
@@ -65,28 +65,28 @@ describe('xterm.js', function() {
         xterm.write('test\n');
       }
 
-      var promptLine = xterm.lines[xterm.ybase + xterm.y];
+      var promptLine = xterm.lines.get(xterm.ybase + xterm.y);
       xterm.clear();
       assert.equal(xterm.y, 0);
       assert.equal(xterm.ybase, 0);
       assert.equal(xterm.ydisp, 0);
       assert.equal(xterm.lines.length, xterm.rows);
-      assert.deepEqual(xterm.lines[0], promptLine);
+      assert.deepEqual(xterm.lines.get(0), promptLine);
       for (var i = 1; i < xterm.rows; i++) {
-        assert.deepEqual(xterm.lines[i], xterm.blankLine());
+        assert.deepEqual(xterm.lines.get(i), xterm.blankLine());
       }
     });
     it('should not break the prompt when cleared twice', function() {
-      var promptLine = xterm.lines[xterm.ybase + xterm.y];
+      var promptLine = xterm.lines.get(xterm.ybase + xterm.y);
       xterm.clear();
       xterm.clear();
       assert.equal(xterm.y, 0);
       assert.equal(xterm.ybase, 0);
       assert.equal(xterm.ydisp, 0);
       assert.equal(xterm.lines.length, xterm.rows);
-      assert.deepEqual(xterm.lines[0], promptLine);
+      assert.deepEqual(xterm.lines.get(0), promptLine);
       for (var i = 1; i < xterm.rows; i++) {
-        assert.deepEqual(xterm.lines[i], xterm.blankLine());
+        assert.deepEqual(xterm.lines.get(i), xterm.blankLine());
       }
     });
   });
@@ -523,11 +523,11 @@ describe('xterm.js', function() {
       var high = String.fromCharCode(0xD800);
       for (var i=0xDC00; i<=0xDCFF; ++i) {
         xterm.write(high + String.fromCharCode(i));
-        var tchar = xterm.lines[0][0];
+        var tchar = xterm.lines.get(0)[0];
         expect(tchar[1]).eql(high + String.fromCharCode(i));
         expect(tchar[1].length).eql(2);
         expect(tchar[2]).eql(1);
-        expect(xterm.lines[0][1][1]).eql(' ');
+        expect(xterm.lines.get(0)[1][1]).eql(' ');
         xterm.reset();
       }
     });
@@ -536,9 +536,9 @@ describe('xterm.js', function() {
       for (var i=0xDC00; i<=0xDCFF; ++i) {
         xterm.x = xterm.cols - 1;
         xterm.write(high + String.fromCharCode(i));
-        expect(xterm.lines[0][xterm.x-1][1]).eql(high + String.fromCharCode(i));
-        expect(xterm.lines[0][xterm.x-1][1].length).eql(2);
-        expect(xterm.lines[1][0][1]).eql(' ');
+        expect(xterm.lines.get(0)[xterm.x-1][1]).eql(high + String.fromCharCode(i));
+        expect(xterm.lines.get(0)[xterm.x-1][1].length).eql(2);
+        expect(xterm.lines.get(1)[0][1]).eql(' ');
         xterm.reset();
       }
     });
@@ -548,10 +548,10 @@ describe('xterm.js', function() {
         xterm.x = xterm.cols - 1;
         xterm.wraparoundMode = true;
         xterm.write('a' + high + String.fromCharCode(i));
-        expect(xterm.lines[0][xterm.cols-1][1]).eql('a');
-        expect(xterm.lines[1][0][1]).eql(high + String.fromCharCode(i));
-        expect(xterm.lines[1][0][1].length).eql(2);
-        expect(xterm.lines[1][1][1]).eql(' ');
+        expect(xterm.lines.get(0)[xterm.cols-1][1]).eql('a');
+        expect(xterm.lines.get(1)[0][1]).eql(high + String.fromCharCode(i));
+        expect(xterm.lines.get(1)[0][1].length).eql(2);
+        expect(xterm.lines.get(1)[1][1]).eql(' ');
         xterm.reset();
       }
     });
@@ -561,9 +561,9 @@ describe('xterm.js', function() {
         xterm.x = xterm.cols - 1;
         xterm.wraparoundMode = false;
         xterm.write('a' + high + String.fromCharCode(i));
-        expect(xterm.lines[0][xterm.cols-1][1]).eql(high + String.fromCharCode(i));
-        expect(xterm.lines[0][xterm.cols-1][1].length).eql(2);
-        expect(xterm.lines[1][1][1]).eql(' ');
+        expect(xterm.lines.get(0)[xterm.cols-1][1]).eql(high + String.fromCharCode(i));
+        expect(xterm.lines.get(0)[xterm.cols-1][1].length).eql(2);
+        expect(xterm.lines.get(1)[1][1]).eql(' ');
         xterm.reset();
       }
     });
@@ -572,11 +572,11 @@ describe('xterm.js', function() {
       for (var i=0xDC00; i<=0xDCFF; ++i) {
         xterm.write(high);
         xterm.write(String.fromCharCode(i));
-        var tchar = xterm.lines[0][0];
+        var tchar = xterm.lines.get(0)[0];
         expect(tchar[1]).eql(high + String.fromCharCode(i));
         expect(tchar[1].length).eql(2);
         expect(tchar[2]).eql(1);
-        expect(xterm.lines[0][1][1]).eql(' ');
+        expect(xterm.lines.get(0)[1][1]).eql(' ');
         xterm.reset();
       }
     });
@@ -585,30 +585,30 @@ describe('xterm.js', function() {
   describe('unicode - combining characters', function() {
     it('café', function () {
       xterm.write('cafe\u0301');
-      expect(xterm.lines[0][3][1]).eql('e\u0301');
-      expect(xterm.lines[0][3][1].length).eql(2);
-      expect(xterm.lines[0][3][2]).eql(1);
+      expect(xterm.lines.get(0)[3][1]).eql('e\u0301');
+      expect(xterm.lines.get(0)[3][1].length).eql(2);
+      expect(xterm.lines.get(0)[3][2]).eql(1);
     });
     it('café - end of line', function() {
       xterm.x = xterm.cols - 1 - 3;
       xterm.write('cafe\u0301');
-      expect(xterm.lines[0][xterm.cols-1][1]).eql('e\u0301');
-      expect(xterm.lines[0][xterm.cols-1][1].length).eql(2);
-      expect(xterm.lines[0][xterm.cols-1][2]).eql(1);
-      expect(xterm.lines[0][1][1]).eql(' ');
-      expect(xterm.lines[0][1][1].length).eql(1);
-      expect(xterm.lines[0][1][2]).eql(1);
+      expect(xterm.lines.get(0)[xterm.cols-1][1]).eql('e\u0301');
+      expect(xterm.lines.get(0)[xterm.cols-1][1].length).eql(2);
+      expect(xterm.lines.get(0)[xterm.cols-1][2]).eql(1);
+      expect(xterm.lines.get(0)[1][1]).eql(' ');
+      expect(xterm.lines.get(0)[1][1].length).eql(1);
+      expect(xterm.lines.get(0)[1][2]).eql(1);
     });
     it('multiple combined é', function() {
       xterm.wraparoundMode = true;
       xterm.write(Array(100).join('e\u0301'));
       for (var i=0; i<xterm.cols; ++i) {
-        var tchar = xterm.lines[0][i];
+        var tchar = xterm.lines.get(0)[i];
         expect(tchar[1]).eql('e\u0301');
         expect(tchar[1].length).eql(2);
         expect(tchar[2]).eql(1);
       }
-      tchar = xterm.lines[1][0];
+      tchar = xterm.lines.get(1)[0];
       expect(tchar[1]).eql('e\u0301');
       expect(tchar[1].length).eql(2);
       expect(tchar[2]).eql(1);
@@ -617,12 +617,12 @@ describe('xterm.js', function() {
       xterm.wraparoundMode = true;
       xterm.write(Array(100).join('\uD800\uDC00\u0301'));
       for (var i=0; i<xterm.cols; ++i) {
-        var tchar = xterm.lines[0][i];
+        var tchar = xterm.lines.get(0)[i];
         expect(tchar[1]).eql('\uD800\uDC00\u0301');
         expect(tchar[1].length).eql(3);
         expect(tchar[2]).eql(1);
       }
-      tchar = xterm.lines[1][0];
+      tchar = xterm.lines.get(1)[0];
       expect(tchar[1]).eql('\uD800\uDC00\u0301');
       expect(tchar[1].length).eql(3);
       expect(tchar[2]).eql(1);
@@ -645,7 +645,7 @@ describe('xterm.js', function() {
       xterm.wraparoundMode = true;
       xterm.write(Array(50).join('¥'));
       for (var i=0; i<xterm.cols; ++i) {
-        var tchar = xterm.lines[0][i];
+        var tchar = xterm.lines.get(0)[i];
         if (i % 2) {
           expect(tchar[1]).eql('');
           expect(tchar[1].length).eql(0);
@@ -656,7 +656,7 @@ describe('xterm.js', function() {
           expect(tchar[2]).eql(2);
         }
       }
-      tchar = xterm.lines[1][0];
+      tchar = xterm.lines.get(1)[0];
       expect(tchar[1]).eql('¥');
       expect(tchar[1].length).eql(1);
       expect(tchar[2]).eql(2);
@@ -666,7 +666,7 @@ describe('xterm.js', function() {
       xterm.x = 1;
       xterm.write(Array(50).join('¥'));
       for (var i=1; i<xterm.cols-1; ++i) {
-        var tchar = xterm.lines[0][i];
+        var tchar = xterm.lines.get(0)[i];
         if (!(i % 2)) {
           expect(tchar[1]).eql('');
           expect(tchar[1].length).eql(0);
@@ -677,11 +677,11 @@ describe('xterm.js', function() {
           expect(tchar[2]).eql(2);
         }
       }
-      tchar = xterm.lines[0][xterm.cols-1];
+      tchar = xterm.lines.get(0)[xterm.cols-1];
       expect(tchar[1]).eql(' ');
       expect(tchar[1].length).eql(1);
       expect(tchar[2]).eql(1);
-      tchar = xterm.lines[1][0];
+      tchar = xterm.lines.get(1)[0];
       expect(tchar[1]).eql('¥');
       expect(tchar[1].length).eql(1);
       expect(tchar[2]).eql(2);
@@ -691,7 +691,7 @@ describe('xterm.js', function() {
       xterm.x = 1;
       xterm.write(Array(50).join('¥\u0301'));
       for (var i=1; i<xterm.cols-1; ++i) {
-        var tchar = xterm.lines[0][i];
+        var tchar = xterm.lines.get(0)[i];
         if (!(i % 2)) {
           expect(tchar[1]).eql('');
           expect(tchar[1].length).eql(0);
@@ -702,11 +702,11 @@ describe('xterm.js', function() {
           expect(tchar[2]).eql(2);
         }
       }
-      tchar = xterm.lines[0][xterm.cols-1];
+      tchar = xterm.lines.get(0)[xterm.cols-1];
       expect(tchar[1]).eql(' ');
       expect(tchar[1].length).eql(1);
       expect(tchar[2]).eql(1);
-      tchar = xterm.lines[1][0];
+      tchar = xterm.lines.get(1)[0];
       expect(tchar[1]).eql('¥\u0301');
       expect(tchar[1].length).eql(2);
       expect(tchar[2]).eql(2);
@@ -715,7 +715,7 @@ describe('xterm.js', function() {
       xterm.wraparoundMode = true;
       xterm.write(Array(50).join('¥\u0301'));
       for (var i=0; i<xterm.cols; ++i) {
-        var tchar = xterm.lines[0][i];
+        var tchar = xterm.lines.get(0)[i];
         if (i % 2) {
           expect(tchar[1]).eql('');
           expect(tchar[1].length).eql(0);
@@ -726,7 +726,7 @@ describe('xterm.js', function() {
           expect(tchar[2]).eql(2);
         }
       }
-      tchar = xterm.lines[1][0];
+      tchar = xterm.lines.get(1)[0];
       expect(tchar[1]).eql('¥\u0301');
       expect(tchar[1].length).eql(2);
       expect(tchar[2]).eql(2);
@@ -736,7 +736,7 @@ describe('xterm.js', function() {
       xterm.x = 1;
       xterm.write(Array(50).join('\ud843\ude6d\u0301'));
       for (var i=1; i<xterm.cols-1; ++i) {
-        var tchar = xterm.lines[0][i];
+        var tchar = xterm.lines.get(0)[i];
         if (!(i % 2)) {
           expect(tchar[1]).eql('');
           expect(tchar[1].length).eql(0);
@@ -747,11 +747,11 @@ describe('xterm.js', function() {
           expect(tchar[2]).eql(2);
         }
       }
-      tchar = xterm.lines[0][xterm.cols-1];
+    tchar = xterm.lines.get(0)[xterm.cols-1];
       expect(tchar[1]).eql(' ');
       expect(tchar[1].length).eql(1);
       expect(tchar[2]).eql(1);
-      tchar = xterm.lines[1][0];
+      tchar = xterm.lines.get(1)[0];
       expect(tchar[1]).eql('\ud843\ude6d\u0301');
       expect(tchar[1].length).eql(3);
       expect(tchar[2]).eql(2);
@@ -760,7 +760,7 @@ describe('xterm.js', function() {
       xterm.wraparoundMode = true;
       xterm.write(Array(50).join('\ud843\ude6d\u0301'));
       for (var i=0; i<xterm.cols; ++i) {
-        var tchar = xterm.lines[0][i];
+        var tchar = xterm.lines.get(0)[i];
         if (i % 2) {
           expect(tchar[1]).eql('');
           expect(tchar[1].length).eql(0);
@@ -771,7 +771,7 @@ describe('xterm.js', function() {
           expect(tchar[2]).eql(2);
         }
       }
-      tchar = xterm.lines[1][0];
+      tchar = xterm.lines.get(1)[0];
       expect(tchar[1]).eql('\ud843\ude6d\u0301');
       expect(tchar[1].length).eql(3);
       expect(tchar[2]).eql(2);
@@ -785,11 +785,11 @@ describe('xterm.js', function() {
       xterm.y = 0;
       xterm.insertMode = true;
       xterm.write('abcde');
-      expect(xterm.lines[0].length).eql(xterm.cols);
-      expect(xterm.lines[0][10][1]).eql('a');
-      expect(xterm.lines[0][14][1]).eql('e');
-      expect(xterm.lines[0][15][1]).eql('0');
-      expect(xterm.lines[0][79][1]).eql('4');
+      expect(xterm.lines.get(0).length).eql(xterm.cols);
+      expect(xterm.lines.get(0)[10][1]).eql('a');
+      expect(xterm.lines.get(0)[14][1]).eql('e');
+      expect(xterm.lines.get(0)[15][1]).eql('0');
+      expect(xterm.lines.get(0)[79][1]).eql('4');
     });
     it('fullwidth - insert', function() {
       xterm.write(Array(9).join('0123456789').slice(-80));
@@ -797,12 +797,12 @@ describe('xterm.js', function() {
       xterm.y = 0;
       xterm.insertMode = true;
       xterm.write('¥¥¥');
-      expect(xterm.lines[0].length).eql(xterm.cols);
-      expect(xterm.lines[0][10][1]).eql('¥');
-      expect(xterm.lines[0][11][1]).eql('');
-      expect(xterm.lines[0][14][1]).eql('¥');
-      expect(xterm.lines[0][15][1]).eql('');
-      expect(xterm.lines[0][79][1]).eql('3');
+      expect(xterm.lines.get(0).length).eql(xterm.cols);
+      expect(xterm.lines.get(0)[10][1]).eql('¥');
+      expect(xterm.lines.get(0)[11][1]).eql('');
+      expect(xterm.lines.get(0)[14][1]).eql('¥');
+      expect(xterm.lines.get(0)[15][1]).eql('');
+      expect(xterm.lines.get(0)[79][1]).eql('3');
     });
     it('fullwidth - right border', function() {
       xterm.write(Array(41).join('¥'));
@@ -810,15 +810,15 @@ describe('xterm.js', function() {
       xterm.y = 0;
       xterm.insertMode = true;
       xterm.write('a');
-      expect(xterm.lines[0].length).eql(xterm.cols);
-      expect(xterm.lines[0][10][1]).eql('a');
-      expect(xterm.lines[0][11][1]).eql('¥');
-      expect(xterm.lines[0][79][1]).eql(' ');  // fullwidth char got replaced
+      expect(xterm.lines.get(0).length).eql(xterm.cols);
+      expect(xterm.lines.get(0)[10][1]).eql('a');
+      expect(xterm.lines.get(0)[11][1]).eql('¥');
+      expect(xterm.lines.get(0)[79][1]).eql(' ');  // fullwidth char got replaced
       xterm.write('b');
-      expect(xterm.lines[0].length).eql(xterm.cols);
-      expect(xterm.lines[0][11][1]).eql('b');
-      expect(xterm.lines[0][12][1]).eql('¥');
-      expect(xterm.lines[0][79][1]).eql('');  // empty cell after fullwidth
+      expect(xterm.lines.get(0).length).eql(xterm.cols);
+      expect(xterm.lines.get(0)[11][1]).eql('b');
+      expect(xterm.lines.get(0)[12][1]).eql('¥');
+      expect(xterm.lines.get(0)[79][1]).eql('');  // empty cell after fullwidth
     });
   });
 });
index a131bcbd73563aef888e65e6188a3f46e8386aab..90659544fc04591e242c1d34f4cb3a7a985c3503 100644 (file)
@@ -93,6 +93,11 @@ export class CircularList<T> {
     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) {
index c88423d437aad6d487c9201dbbd2e320be6dc0c1..72394147255c444908bdda3b399c6cf6e8aa36ac 100644 (file)
@@ -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<ch_width; ++moves) {
                   // remove last cell, if it's width is 0
                   // we have to adjust the second last cell as well
-                  var removed = this.lines[this.y + this.ybase].pop();
+                  var removed = this.lines.get(this.y + this.ybase).pop();
                   if (removed[2]===0
-                      && this.lines[row][this.cols-2]
-                      && this.lines[row][this.cols-2][2]===2)
-                    this.lines[row][this.cols-2] = [this.curAttr, ' ', 1];
+                      && this.lines.get(row)[this.cols-2]
+                  && this.lines.get(row)[this.cols-2][2]===2)
+                    this.lines.get(row)[this.cols-2] = [this.curAttr, ' ', 1];
 
                   // insert empty cell at cursor
-                  this.lines[row].splice(this.x, 0, [this.curAttr, ' ', 1]);
+                  this.lines.get(row).splice(this.x, 0, [this.curAttr, ' ', 1]);
                 }
               }
 
-              this.lines[row][this.x] = [this.curAttr, ch, ch_width];
+              this.lines.get(row)[this.x] = [this.curAttr, ch, ch_width];
               this.x++;
               this.updateRange(this.y);
 
               // fullwidth char - set next cell width to zero and advance cursor
               if (ch_width===2) {
-                this.lines[row][this.x] = [this.curAttr, '', 0];
+                this.lines.get(row)[this.x] = [this.curAttr, '', 0];
                 this.x++;
               }
             }
@@ -2881,15 +2881,15 @@ Terminal.prototype.resize = function(x, y) {
     ch = [this.defAttr, ' ', 1]; // does xterm use the default attr?
     i = this.lines.length;
     while (i--) {
-      while (this.lines[i].length < x) {
-        this.lines[i].push(ch);
+      while (this.lines.get(i).length < x) {
+        this.lines.get(i).push(ch);
       }
     }
   } else { // (j > 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;
     }