Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xterm

Package Overview
Dependencies
Maintainers
2
Versions
1092
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xterm - npm Package Compare versions

Comparing version 3.14.0-beta8 to 3.14.0-beta9

425

lib/public/Terminal.api.js

@@ -121,3 +121,3 @@ "use strict";

_b = (_a = chai_1.assert).equal;
return [4, page.evaluate("window.term._core.buffer.translateBufferLineToString(0, true)")];
return [4, page.evaluate("window.term.buffer.getLine(0).translateToString(true)")];
case 3:

@@ -144,7 +144,7 @@ _b.apply(_a, [_c.sent(), 'foobar']);

_b = (_a = chai_1.assert).equal;
return [4, page.evaluate("window.term._core.buffer.translateBufferLineToString(0, true)")];
return [4, page.evaluate("window.term.buffer.getLine(0).translateToString(true)")];
case 3:
_b.apply(_a, [_e.sent(), 'foo']);
_d = (_c = chai_1.assert).equal;
return [4, page.evaluate("window.term._core.buffer.translateBufferLineToString(1, true)")];
return [4, page.evaluate("window.term.buffer.getLine(1).translateToString(true)")];
case 4:

@@ -174,7 +174,7 @@ _d.apply(_c, [_e.sent(), 'bar']);

_b = (_a = chai_1.assert).equal;
return [4, page.evaluate("window.term._core.buffer.lines.length")];
return [4, page.evaluate("window.term.buffer.length")];
case 4:
_b.apply(_a, [_g.sent(), '5']);
_d = (_c = chai_1.assert).equal;
return [4, page.evaluate("window.term._core.buffer.translateBufferLineToString(0, true)")];
return [4, page.evaluate("window.term.buffer.getLine(0).translateToString(true)")];
case 5:

@@ -187,3 +187,3 @@ _d.apply(_c, [_g.sent(), 'test9']);

_f = (_e = chai_1.assert).equal;
return [4, page.evaluate("window.term._core.buffer.translateBufferLineToString(" + i + ", true)")];
return [4, page.evaluate("window.term.buffer.getLine(" + i + ").translateToString(true)")];
case 7:

@@ -590,2 +590,415 @@ _f.apply(_e, [_g.sent(), '']);

});
describe('buffer', function () {
it('cursorX, cursorY', function () {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
return __generator(this, function (_0) {
switch (_0.label) {
case 0:
this.timeout(10000);
return [4, openTerminal({ rows: 5, cols: 5 })];
case 1:
_0.sent();
_b = (_a = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.cursorX")];
case 2:
_b.apply(_a, [_0.sent(), 0]);
_d = (_c = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.cursorY")];
case 3:
_d.apply(_c, [_0.sent(), 0]);
return [4, page.evaluate("window.term.write('foo')")];
case 4:
_0.sent();
_f = (_e = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.cursorX")];
case 5:
_f.apply(_e, [_0.sent(), 3]);
_h = (_g = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.cursorY")];
case 6:
_h.apply(_g, [_0.sent(), 0]);
return [4, page.evaluate("window.term.write('\\n')")];
case 7:
_0.sent();
_k = (_j = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.cursorX")];
case 8:
_k.apply(_j, [_0.sent(), 3]);
_m = (_l = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.cursorY")];
case 9:
_m.apply(_l, [_0.sent(), 1]);
return [4, page.evaluate("window.term.write('\\r')")];
case 10:
_0.sent();
_p = (_o = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.cursorX")];
case 11:
_p.apply(_o, [_0.sent(), 0]);
_r = (_q = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.cursorY")];
case 12:
_r.apply(_q, [_0.sent(), 1]);
return [4, page.evaluate("window.term.write('abcde')")];
case 13:
_0.sent();
_t = (_s = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.cursorX")];
case 14:
_t.apply(_s, [_0.sent(), 5]);
_v = (_u = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.cursorY")];
case 15:
_v.apply(_u, [_0.sent(), 1]);
return [4, page.evaluate("window.term.write('\\n\\r\\n\\n\\n\\n\\n')")];
case 16:
_0.sent();
_x = (_w = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.cursorX")];
case 17:
_x.apply(_w, [_0.sent(), 0]);
_z = (_y = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.cursorY")];
case 18:
_z.apply(_y, [_0.sent(), 4]);
return [2];
}
});
});
});
it('viewportY', function () {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
return __generator(this, function (_o) {
switch (_o.label) {
case 0:
this.timeout(10000);
return [4, openTerminal({ rows: 5 })];
case 1:
_o.sent();
_b = (_a = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.viewportY")];
case 2:
_b.apply(_a, [_o.sent(), 0]);
return [4, page.evaluate("window.term.write('\\n\\n\\n\\n')")];
case 3:
_o.sent();
_d = (_c = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.viewportY")];
case 4:
_d.apply(_c, [_o.sent(), 0]);
return [4, page.evaluate("window.term.write('\\n')")];
case 5:
_o.sent();
_f = (_e = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.viewportY")];
case 6:
_f.apply(_e, [_o.sent(), 1]);
return [4, page.evaluate("window.term.write('\\n\\n\\n\\n')")];
case 7:
_o.sent();
_h = (_g = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.viewportY")];
case 8:
_h.apply(_g, [_o.sent(), 5]);
return [4, page.evaluate("window.term.scrollLines(-1)")];
case 9:
_o.sent();
_k = (_j = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.viewportY")];
case 10:
_k.apply(_j, [_o.sent(), 4]);
return [4, page.evaluate("window.term.scrollToTop()")];
case 11:
_o.sent();
_m = (_l = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.viewportY")];
case 12:
_m.apply(_l, [_o.sent(), 0]);
return [2];
}
});
});
});
it('baseY', function () {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
return __generator(this, function (_o) {
switch (_o.label) {
case 0:
this.timeout(10000);
return [4, openTerminal({ rows: 5 })];
case 1:
_o.sent();
_b = (_a = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.baseY")];
case 2:
_b.apply(_a, [_o.sent(), 0]);
return [4, page.evaluate("window.term.write('\\n\\n\\n\\n')")];
case 3:
_o.sent();
_d = (_c = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.baseY")];
case 4:
_d.apply(_c, [_o.sent(), 0]);
return [4, page.evaluate("window.term.write('\\n')")];
case 5:
_o.sent();
_f = (_e = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.baseY")];
case 6:
_f.apply(_e, [_o.sent(), 1]);
return [4, page.evaluate("window.term.write('\\n\\n\\n\\n')")];
case 7:
_o.sent();
_h = (_g = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.baseY")];
case 8:
_h.apply(_g, [_o.sent(), 5]);
return [4, page.evaluate("window.term.scrollLines(-1)")];
case 9:
_o.sent();
_k = (_j = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.baseY")];
case 10:
_k.apply(_j, [_o.sent(), 5]);
return [4, page.evaluate("window.term.scrollToTop()")];
case 11:
_o.sent();
_m = (_l = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.baseY")];
case 12:
_m.apply(_l, [_o.sent(), 5]);
return [2];
}
});
});
});
it('length', function () {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c, _d, _e, _f, _g, _h;
return __generator(this, function (_j) {
switch (_j.label) {
case 0:
this.timeout(10000);
return [4, openTerminal({ rows: 5 })];
case 1:
_j.sent();
_b = (_a = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.length")];
case 2:
_b.apply(_a, [_j.sent(), 5]);
return [4, page.evaluate("window.term.write('\\n\\n\\n\\n')")];
case 3:
_j.sent();
_d = (_c = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.length")];
case 4:
_d.apply(_c, [_j.sent(), 5]);
return [4, page.evaluate("window.term.write('\\n')")];
case 5:
_j.sent();
_f = (_e = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.length")];
case 6:
_f.apply(_e, [_j.sent(), 6]);
return [4, page.evaluate("window.term.write('\\n\\n\\n\\n')")];
case 7:
_j.sent();
_h = (_g = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.length")];
case 8:
_h.apply(_g, [_j.sent(), 10]);
return [2];
}
});
});
});
describe('getLine', function () {
it('invalid index', function () {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
this.timeout(10000);
return [4, openTerminal({ rows: 5 })];
case 1:
_e.sent();
_b = (_a = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(-1)")];
case 2:
_b.apply(_a, [_e.sent(), undefined]);
_d = (_c = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(5)")];
case 3:
_d.apply(_c, [_e.sent(), undefined]);
return [2];
}
});
});
});
it('isWrapped', function () {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
return __generator(this, function (_o) {
switch (_o.label) {
case 0:
this.timeout(10000);
return [4, openTerminal({ cols: 5 })];
case 1:
_o.sent();
_b = (_a = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).isWrapped")];
case 2:
_b.apply(_a, [_o.sent(), false]);
_d = (_c = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(1).isWrapped")];
case 3:
_d.apply(_c, [_o.sent(), false]);
return [4, page.evaluate("window.term.write('abcde')")];
case 4:
_o.sent();
_f = (_e = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).isWrapped")];
case 5:
_f.apply(_e, [_o.sent(), false]);
_h = (_g = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(1).isWrapped")];
case 6:
_h.apply(_g, [_o.sent(), false]);
return [4, page.evaluate("window.term.write('f')")];
case 7:
_o.sent();
_k = (_j = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).isWrapped")];
case 8:
_k.apply(_j, [_o.sent(), false]);
_m = (_l = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(1).isWrapped")];
case 9:
_m.apply(_l, [_o.sent(), true]);
return [2];
}
});
});
});
it('translateToString', function () {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
return __generator(this, function (_u) {
switch (_u.label) {
case 0:
this.timeout(10000);
return [4, openTerminal({ cols: 5 })];
case 1:
_u.sent();
_b = (_a = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).translateToString()")];
case 2:
_b.apply(_a, [_u.sent(), ' ']);
_d = (_c = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).translateToString(true)")];
case 3:
_d.apply(_c, [_u.sent(), '']);
return [4, page.evaluate("window.term.write('foo')")];
case 4:
_u.sent();
_f = (_e = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).translateToString()")];
case 5:
_f.apply(_e, [_u.sent(), 'foo ']);
_h = (_g = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).translateToString(true)")];
case 6:
_h.apply(_g, [_u.sent(), 'foo']);
return [4, page.evaluate("window.term.write('bar')")];
case 7:
_u.sent();
_k = (_j = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).translateToString()")];
case 8:
_k.apply(_j, [_u.sent(), 'fooba']);
_m = (_l = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).translateToString(true)")];
case 9:
_m.apply(_l, [_u.sent(), 'fooba']);
_p = (_o = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(1).translateToString(true)")];
case 10:
_p.apply(_o, [_u.sent(), 'r']);
_r = (_q = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).translateToString(false, 1)")];
case 11:
_r.apply(_q, [_u.sent(), 'ooba']);
_t = (_s = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).translateToString(false, 1, 3)")];
case 12:
_t.apply(_s, [_u.sent(), 'oo']);
return [2];
}
});
});
});
it('getCell', function () {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
return __generator(this, function (_w) {
switch (_w.label) {
case 0:
this.timeout(10000);
return [4, openTerminal({ cols: 5 })];
case 1:
_w.sent();
_b = (_a = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).getCell(-1)")];
case 2:
_b.apply(_a, [_w.sent(), undefined]);
_d = (_c = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).getCell(5)")];
case 3:
_d.apply(_c, [_w.sent(), undefined]);
_f = (_e = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).getCell(0).char")];
case 4:
_f.apply(_e, [_w.sent(), '']);
_h = (_g = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).getCell(0).width")];
case 5:
_h.apply(_g, [_w.sent(), 1]);
return [4, page.evaluate("window.term.write('a\u6587')")];
case 6:
_w.sent();
_k = (_j = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).getCell(0).char")];
case 7:
_k.apply(_j, [_w.sent(), 'a']);
_m = (_l = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).getCell(0).width")];
case 8:
_m.apply(_l, [_w.sent(), 1]);
_p = (_o = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).getCell(1).char")];
case 9:
_p.apply(_o, [_w.sent(), '文']);
_r = (_q = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).getCell(1).width")];
case 10:
_r.apply(_q, [_w.sent(), 2]);
_t = (_s = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).getCell(2).char")];
case 11:
_t.apply(_s, [_w.sent(), '']);
_v = (_u = chai_1.assert).equal;
return [4, page.evaluate("window.term.buffer.getLine(0).getCell(2).width")];
case 12:
_v.apply(_u, [_w.sent(), 0]);
return [2];
}
});
});
});
});
});
});

@@ -592,0 +1005,0 @@ function openTerminal(options) {

@@ -74,2 +74,7 @@ "use strict";

});
Object.defineProperty(Terminal.prototype, "buffer", {
get: function () { return new BufferApiView(this._core.buffer); },
enumerable: true,
configurable: true
});
Object.defineProperty(Terminal.prototype, "markers", {

@@ -198,2 +203,77 @@ get: function () { return this._core.markers; },

exports.Terminal = Terminal;
var BufferApiView = (function () {
function BufferApiView(_buffer) {
this._buffer = _buffer;
}
Object.defineProperty(BufferApiView.prototype, "cursorY", {
get: function () { return this._buffer.y; },
enumerable: true,
configurable: true
});
Object.defineProperty(BufferApiView.prototype, "cursorX", {
get: function () { return this._buffer.x; },
enumerable: true,
configurable: true
});
Object.defineProperty(BufferApiView.prototype, "viewportY", {
get: function () { return this._buffer.ydisp; },
enumerable: true,
configurable: true
});
Object.defineProperty(BufferApiView.prototype, "baseY", {
get: function () { return this._buffer.ybase; },
enumerable: true,
configurable: true
});
Object.defineProperty(BufferApiView.prototype, "length", {
get: function () { return this._buffer.lines.length; },
enumerable: true,
configurable: true
});
BufferApiView.prototype.getLine = function (y) {
var line = this._buffer.lines.get(y);
if (!line) {
return undefined;
}
return new BufferLineApiView(line);
};
return BufferApiView;
}());
var BufferLineApiView = (function () {
function BufferLineApiView(_line) {
this._line = _line;
}
Object.defineProperty(BufferLineApiView.prototype, "isWrapped", {
get: function () { return this._line.isWrapped; },
enumerable: true,
configurable: true
});
BufferLineApiView.prototype.getCell = function (x) {
if (x < 0 || x >= this._line.length) {
return undefined;
}
return new BufferCellApiView(this._line, x);
};
BufferLineApiView.prototype.translateToString = function (trimRight, startColumn, endColumn) {
return this._line.translateToString(trimRight, startColumn, endColumn);
};
return BufferLineApiView;
}());
var BufferCellApiView = (function () {
function BufferCellApiView(_line, _x) {
this._line = _line;
this._x = _x;
}
Object.defineProperty(BufferCellApiView.prototype, "char", {
get: function () { return this._line.getString(this._x); },
enumerable: true,
configurable: true
});
Object.defineProperty(BufferCellApiView.prototype, "width", {
get: function () { return this._line.getWidth(this._x); },
enumerable: true,
configurable: true
});
return BufferCellApiView;
}());
//# sourceMappingURL=Terminal.js.map

4

lib/renderer/dom/DomRenderer.js

@@ -138,4 +138,4 @@ "use strict";

(" background-color: " + this.colorManager.colors.background.css + ";") +
(" font-family: " + this._terminal.getOption('fontFamily') + ";") +
(" font-size: " + this._terminal.getOption('fontSize') + "px;") +
(" font-family: " + this._terminal.options.fontFamily + ";") +
(" font-size: " + this._terminal.options.fontSize + "px;") +
"}";

@@ -142,0 +142,0 @@ styles +=

{
"name": "xterm",
"description": "Full xterm terminal, in your browser",
"version": "3.14.0-beta8",
"version": "3.14.0-beta9",
"main": "lib/public/Terminal.js",

@@ -6,0 +6,0 @@ "types": "typings/xterm.d.ts",

@@ -51,3 +51,3 @@ /**

`);
assert.equal(await page.evaluate(`window.term._core.buffer.translateBufferLineToString(0, true)`), 'foobar');
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString(true)`), 'foobar');
});

@@ -62,4 +62,4 @@

`);
assert.equal(await page.evaluate(`window.term._core.buffer.translateBufferLineToString(0, true)`), 'foo');
assert.equal(await page.evaluate(`window.term._core.buffer.translateBufferLineToString(1, true)`), 'bar');
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString(true)`), 'foo');
assert.equal(await page.evaluate(`window.term.buffer.getLine(1).translateToString(true)`), 'bar');
});

@@ -77,6 +77,6 @@

await page.evaluate(`window.term.clear()`);
assert.equal(await page.evaluate(`window.term._core.buffer.lines.length`), '5');
assert.equal(await page.evaluate(`window.term._core.buffer.translateBufferLineToString(0, true)`), 'test9');
assert.equal(await page.evaluate(`window.term.buffer.length`), '5');
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString(true)`), 'test9');
for (let i = 1; i < 5; i++) {
assert.equal(await page.evaluate(`window.term._core.buffer.translateBufferLineToString(${i}, true)`), '');
assert.equal(await page.evaluate(`window.term.buffer.getLine(${i}).translateToString(true)`), '');
}

@@ -237,2 +237,124 @@ });

});
describe('buffer', () => {
it('cursorX, cursorY', async function(): Promise<any> {
this.timeout(10000);
await openTerminal({ rows: 5, cols: 5 });
assert.equal(await page.evaluate(`window.term.buffer.cursorX`), 0);
assert.equal(await page.evaluate(`window.term.buffer.cursorY`), 0);
await page.evaluate(`window.term.write('foo')`);
assert.equal(await page.evaluate(`window.term.buffer.cursorX`), 3);
assert.equal(await page.evaluate(`window.term.buffer.cursorY`), 0);
await page.evaluate(`window.term.write('\\n')`);
assert.equal(await page.evaluate(`window.term.buffer.cursorX`), 3);
assert.equal(await page.evaluate(`window.term.buffer.cursorY`), 1);
await page.evaluate(`window.term.write('\\r')`);
assert.equal(await page.evaluate(`window.term.buffer.cursorX`), 0);
assert.equal(await page.evaluate(`window.term.buffer.cursorY`), 1);
await page.evaluate(`window.term.write('abcde')`);
assert.equal(await page.evaluate(`window.term.buffer.cursorX`), 5);
assert.equal(await page.evaluate(`window.term.buffer.cursorY`), 1);
await page.evaluate(`window.term.write('\\n\\r\\n\\n\\n\\n\\n')`);
assert.equal(await page.evaluate(`window.term.buffer.cursorX`), 0);
assert.equal(await page.evaluate(`window.term.buffer.cursorY`), 4);
});
it('viewportY', async function(): Promise<any> {
this.timeout(10000);
await openTerminal({ rows: 5 });
assert.equal(await page.evaluate(`window.term.buffer.viewportY`), 0);
await page.evaluate(`window.term.write('\\n\\n\\n\\n')`);
assert.equal(await page.evaluate(`window.term.buffer.viewportY`), 0);
await page.evaluate(`window.term.write('\\n')`);
assert.equal(await page.evaluate(`window.term.buffer.viewportY`), 1);
await page.evaluate(`window.term.write('\\n\\n\\n\\n')`);
assert.equal(await page.evaluate(`window.term.buffer.viewportY`), 5);
await page.evaluate(`window.term.scrollLines(-1)`);
assert.equal(await page.evaluate(`window.term.buffer.viewportY`), 4);
await page.evaluate(`window.term.scrollToTop()`);
assert.equal(await page.evaluate(`window.term.buffer.viewportY`), 0);
});
it('baseY', async function(): Promise<any> {
this.timeout(10000);
await openTerminal({ rows: 5 });
assert.equal(await page.evaluate(`window.term.buffer.baseY`), 0);
await page.evaluate(`window.term.write('\\n\\n\\n\\n')`);
assert.equal(await page.evaluate(`window.term.buffer.baseY`), 0);
await page.evaluate(`window.term.write('\\n')`);
assert.equal(await page.evaluate(`window.term.buffer.baseY`), 1);
await page.evaluate(`window.term.write('\\n\\n\\n\\n')`);
assert.equal(await page.evaluate(`window.term.buffer.baseY`), 5);
await page.evaluate(`window.term.scrollLines(-1)`);
assert.equal(await page.evaluate(`window.term.buffer.baseY`), 5);
await page.evaluate(`window.term.scrollToTop()`);
assert.equal(await page.evaluate(`window.term.buffer.baseY`), 5);
});
it('length', async function(): Promise<any> {
this.timeout(10000);
await openTerminal({ rows: 5 });
assert.equal(await page.evaluate(`window.term.buffer.length`), 5);
await page.evaluate(`window.term.write('\\n\\n\\n\\n')`);
assert.equal(await page.evaluate(`window.term.buffer.length`), 5);
await page.evaluate(`window.term.write('\\n')`);
assert.equal(await page.evaluate(`window.term.buffer.length`), 6);
await page.evaluate(`window.term.write('\\n\\n\\n\\n')`);
assert.equal(await page.evaluate(`window.term.buffer.length`), 10);
});
describe('getLine', () => {
it('invalid index', async function(): Promise<any> {
this.timeout(10000);
await openTerminal({ rows: 5 });
assert.equal(await page.evaluate(`window.term.buffer.getLine(-1)`), undefined);
assert.equal(await page.evaluate(`window.term.buffer.getLine(5)`), undefined);
});
it('isWrapped', async function(): Promise<any> {
this.timeout(10000);
await openTerminal({ cols: 5 });
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).isWrapped`), false);
assert.equal(await page.evaluate(`window.term.buffer.getLine(1).isWrapped`), false);
await page.evaluate(`window.term.write('abcde')`);
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).isWrapped`), false);
assert.equal(await page.evaluate(`window.term.buffer.getLine(1).isWrapped`), false);
await page.evaluate(`window.term.write('f')`);
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).isWrapped`), false);
assert.equal(await page.evaluate(`window.term.buffer.getLine(1).isWrapped`), true);
});
it('translateToString', async function(): Promise<any> {
this.timeout(10000);
await openTerminal({ cols: 5 });
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString()`), ' ');
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString(true)`), '');
await page.evaluate(`window.term.write('foo')`);
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString()`), 'foo ');
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString(true)`), 'foo');
await page.evaluate(`window.term.write('bar')`);
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString()`), 'fooba');
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString(true)`), 'fooba');
assert.equal(await page.evaluate(`window.term.buffer.getLine(1).translateToString(true)`), 'r');
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString(false, 1)`), 'ooba');
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString(false, 1, 3)`), 'oo');
});
it('getCell', async function(): Promise<any> {
this.timeout(10000);
await openTerminal({ cols: 5 });
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(-1)`), undefined);
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(5)`), undefined);
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(0).char`), '');
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(0).width`), 1);
await page.evaluate(`window.term.write('a文')`);
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(0).char`), 'a');
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(0).width`), 1);
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(1).char`), '文');
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(1).width`), 2);
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(2).char`), '');
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(2).width`), 0);
});
});
});
});

@@ -239,0 +361,0 @@

@@ -6,4 +6,5 @@ /**

import { Terminal as ITerminalApi, ITerminalOptions, IMarker, IDisposable, ILinkMatcherOptions, ITheme, ILocalizableStrings } from 'xterm';
import { ITerminal } from '../Types';
import { Terminal as ITerminalApi, ITerminalOptions, IMarker, IDisposable, ILinkMatcherOptions, ITheme, ILocalizableStrings, IBuffer as IBufferApi, IBufferLine as IBufferLineApi, IBufferCell as IBufferCellApi } from 'xterm';
import { ITerminal, IBuffer } from '../Types';
import { IBufferLine } from '../core/Types';
import { Terminal as TerminalCore } from '../Terminal';

@@ -34,2 +35,3 @@ import * as Strings from '../Strings';

public get cols(): number { return this._core.cols; }
public get buffer(): IBufferApi { return new BufferApiView(this._core.buffer); }
public get markers(): ReadonlyArray<IMarker> { return this._core.markers; }

@@ -174,1 +176,39 @@ public blur(): void {

}
class BufferApiView implements IBufferApi {
constructor(private _buffer: IBuffer) {}
public get cursorY(): number { return this._buffer.y; }
public get cursorX(): number { return this._buffer.x; }
public get viewportY(): number { return this._buffer.ydisp; }
public get baseY(): number { return this._buffer.ybase; }
public get length(): number { return this._buffer.lines.length; }
public getLine(y: number): IBufferLineApi | undefined {
const line = this._buffer.lines.get(y);
if (!line) {
return undefined;
}
return new BufferLineApiView(line);
}
}
class BufferLineApiView implements IBufferLineApi {
constructor(private _line: IBufferLine) {}
public get isWrapped(): boolean { return this._line.isWrapped; }
public getCell(x: number): IBufferCellApi | undefined {
if (x < 0 || x >= this._line.length) {
return undefined;
}
return new BufferCellApiView(this._line, x);
}
public translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string {
return this._line.translateToString(trimRight, startColumn, endColumn);
}
}
class BufferCellApiView implements IBufferCellApi {
constructor(private _line: IBufferLine, private _x: number) {}
public get char(): string { return this._line.getString(this._x); }
public get width(): number { return this._line.getWidth(this._x); }
}

@@ -160,4 +160,4 @@ /**

` background-color: ${this.colorManager.colors.background.css};` +
` font-family: ${this._terminal.getOption('fontFamily')};` +
` font-size: ${this._terminal.getOption('fontSize')}px;` +
` font-family: ${this._terminal.options.fontFamily};` +
` font-size: ${this._terminal.options.fontSize}px;` +
`}`;

@@ -164,0 +164,0 @@ // Text styles

@@ -6,3 +6,3 @@ /**

import { Terminal as PublicTerminal, ITerminalOptions as IPublicTerminalOptions, IEventEmitter, IDisposable } from 'xterm';
import { ITerminalOptions as IPublicTerminalOptions, IEventEmitter, IDisposable, IMarker } from 'xterm';
import { IColorSet, IRenderer } from './renderer/Types';

@@ -199,3 +199,3 @@ import { ICharset, IAttributeData, ICellData, IBufferLine, CharData } from './core/Types';

export interface ITerminal extends PublicTerminal, IElementAccessor, IBufferAccessor, ILinkifierAccessor {
export interface ITerminal extends IPublicTerminal, IElementAccessor, IBufferAccessor, ILinkifierAccessor {
screenElement: HTMLElement;

@@ -225,2 +225,50 @@ selectionManager: ISelectionManager;

export interface IPublicTerminal extends IDisposable, IEventEmitter {
textarea: HTMLTextAreaElement;
rows: number;
cols: number;
buffer: IBuffer;
markers: IMarker[];
onCursorMove: IEvent<void>;
onData: IEvent<string>;
onKey: IEvent<{ key: string, domEvent: KeyboardEvent }>;
onLineFeed: IEvent<void>;
onScroll: IEvent<number>;
onSelectionChange: IEvent<void>;
onRender: IEvent<{ start: number, end: number }>;
onResize: IEvent<{ cols: number, rows: number }>;
onTitleChange: IEvent<string>;
blur(): void;
focus(): void;
resize(columns: number, rows: number): void;
writeln(data: string): void;
open(parent: HTMLElement): void;
attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;
addCsiHandler(flag: string, callback: (params: number[], collect: string) => boolean): IDisposable;
addOscHandler(ident: number, callback: (data: string) => boolean): IDisposable;
registerLinkMatcher(regex: RegExp, handler: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions): number;
deregisterLinkMatcher(matcherId: number): void;
registerCharacterJoiner(handler: (text: string) => [number, number][]): number;
deregisterCharacterJoiner(joinerId: number): void;
addMarker(cursorYOffset: number): IMarker;
hasSelection(): boolean;
getSelection(): string;
clearSelection(): void;
selectAll(): void;
selectLines(start: number, end: number): void;
dispose(): void;
destroy(): void;
scrollLines(amount: number): void;
scrollPages(pageCount: number): void;
scrollToTop(): void;
scrollToBottom(): void;
scrollToLine(line: number): void;
clear(): void;
write(data: string): void;
getOption(key: string): any;
setOption(key: string, value: any): void;
refresh(start: number, end: number): void;
reset(): void;
}
export interface IBufferAccessor {

@@ -227,0 +275,0 @@ buffer: IBuffer;

@@ -278,3 +278,3 @@ /**

*/
leaveCallback?: (event: MouseEvent, uri: string) => boolean | void;
leaveCallback?: () => void;

@@ -360,2 +360,9 @@ /**

/**
* (EXPERIMENTAL) The terminal's current buffer, this might be either the
* normal buffer or the alt buffer depending on what's running in the
* terminal.
*/
readonly buffer: IBuffer;
/**
* (EXPERIMENTAL) Get all markers registered against the buffer. If the alt

@@ -861,2 +868,86 @@ * buffer is active this will always return [].

}
interface IBuffer {
/**
* The y position of the cursor. This ranges between `0` (when the
* cursor is at baseY) and `Terminal.rows - 1` (when the cursor is on the
* last row).
*/
readonly cursorY: number;
/**
* The x position of the cursor. This ranges between `0` (left side) and
* `Terminal.cols - 1` (right side).
*/
readonly cursorX: number;
/**
* The line within the buffer where the top of the viewport is.
*/
readonly viewportY: number;
/**
* The line within the buffer where the top of the bottom page is (when
* fully scrolled down);
*/
readonly baseY: number;
/**
* The amount of lines in the buffer.
*/
readonly length: number;
/**
* Gets a line from the buffer, or undefined if the line index does not exist.
*
* Note that the result of this function should be used immediately after calling as when the
* terminal updates it could lead to unexpected behavior.
*
* @param y The line index to get.
*/
getLine(y: number): IBufferLine | undefined;
}
interface IBufferLine {
/**
* Whether the line is wrapped from the previous line.
*/
readonly isWrapped: boolean;
/**
* Gets a cell from the line, or undefined if the line index does not exist.
*
* Note that the result of this function should be used immediately after calling as when the
* terminal updates it could lead to unexpected behavior.
*
* @param x The character index to get.
*/
getCell(x: number): IBufferCell;
/**
* Gets the line as a string. Note that this is gets only the string for the line, not taking
* isWrapped into account.
*
* @param trimRight Whether to trim any whitespace at the right of the line.
* @param startColumn The column to start from (inclusive).
* @param endColumn The column to end at (exclusive).
*/
translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string;
}
interface IBufferCell {
/**
* The character within the cell.
*/
readonly char: string;
/**
* The width of the character. Some examples:
*
* - This is `1` for most cells.
* - This is `2` for wide character like CJK glyphs.
* - This is `0` for cells immediately following cells with a width of `2`.
*/
readonly width: number;
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc