Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a circular list to manage buffer #422

Merged
merged 17 commits into from
Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/test/escape-sequences-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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+$/, '');
Expand All @@ -83,7 +83,6 @@ 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){
Expand All @@ -92,7 +91,7 @@ describe('xterm output comparison', function() {
var in_file = fs.readFileSync(filename, 'utf8');
var from_pty = pty_write_read(in_file);
// uncomment this to get log from terminal
console.log = function(){};
//console.log = function(){};
xterm.write(from_pty);
var from_emulator = terminalToString(xterm);
console.log = CONSOLE_LOG;
Expand Down
140 changes: 70 additions & 70 deletions src/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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());
}
});
});
Expand Down Expand Up @@ -543,11 +543,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();
}
});
Expand All @@ -556,9 +556,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();
}
});
Expand All @@ -568,10 +568,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();
}
});
Expand All @@ -581,9 +581,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();
}
});
Expand All @@ -592,11 +592,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();
}
});
Expand All @@ -605,30 +605,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);
Expand All @@ -637,12 +637,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);
Expand All @@ -665,7 +665,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);
Expand All @@ -676,7 +676,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);
Expand All @@ -686,7 +686,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);
Expand All @@ -697,11 +697,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);
Expand All @@ -711,7 +711,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);
Expand All @@ -722,11 +722,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);
Expand All @@ -735,7 +735,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);
Expand All @@ -746,7 +746,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);
Expand All @@ -756,7 +756,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);
Expand All @@ -767,11 +767,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);
Expand All @@ -780,7 +780,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);
Expand All @@ -791,7 +791,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);
Expand All @@ -805,40 +805,40 @@ 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));
xterm.x = 10;
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('¥'));
xterm.x = 10;
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
});
});
});
Loading