TerminalLine ctor parameters; tests
This commit is contained in:
@@ -0,0 +1,53 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
import * as chai from 'chai';
|
||||||
|
import { TerminalLine } from './TerminalLine';
|
||||||
|
import { CharData } from './Types';
|
||||||
|
import { NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, CHAR_DATA_ATTR_INDEX, CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CODE_INDEX } from './Buffer';
|
||||||
|
|
||||||
|
describe('TerminalLine', function(): void {
|
||||||
|
it('ctor', function(): void {
|
||||||
|
let line = new TerminalLine();
|
||||||
|
chai.expect(line.length).equals(0);
|
||||||
|
chai.expect(line.pop()).equals(undefined);
|
||||||
|
chai.expect(line.isWrapped).equals(false);
|
||||||
|
line = new TerminalLine(10);
|
||||||
|
chai.expect(line.length).equals(10);
|
||||||
|
chai.expect(line.pop()).eql(TerminalLine.defaultCell);
|
||||||
|
chai.expect(line.isWrapped).equals(false);
|
||||||
|
line = new TerminalLine(10, null, true);
|
||||||
|
chai.expect(line.length).equals(10);
|
||||||
|
chai.expect(line.pop()).eql(TerminalLine.defaultCell);
|
||||||
|
chai.expect(line.isWrapped).equals(true);
|
||||||
|
line = new TerminalLine(10, [123, 'a', 456, 789], true);
|
||||||
|
chai.expect(line.length).equals(10);
|
||||||
|
chai.expect(line.pop()).eql([123, 'a', 456, 789]);
|
||||||
|
chai.expect(line.isWrapped).equals(true);
|
||||||
|
});
|
||||||
|
it('splice', function(): void {
|
||||||
|
const line = new TerminalLine();
|
||||||
|
const data: CharData[] = [
|
||||||
|
[1, 'a', 0, 0],
|
||||||
|
[2, 'b', 0, 0],
|
||||||
|
[3, 'c', 0, 0]
|
||||||
|
];
|
||||||
|
for (let i = 0; i < data.length; ++i) line.push(data[i]);
|
||||||
|
chai.expect(line.length).equals(data.length);
|
||||||
|
const removed1 = line.splice(1, 1, [4, 'd', 0, 0]);
|
||||||
|
const removed2 = data.splice(1, 1, [4, 'd', 0, 0]);
|
||||||
|
chai.expect(removed1).eql(removed2);
|
||||||
|
chai.expect(line.toArray()).eql(data);
|
||||||
|
});
|
||||||
|
it('TerminalLine.blankLine', function(): void {
|
||||||
|
const line = TerminalLine.blankLine(5, 123);
|
||||||
|
chai.expect(line.length).equals(5);
|
||||||
|
chai.expect(line.isWrapped).equals(false);
|
||||||
|
const ch = line.get(0);
|
||||||
|
chai.expect(ch[CHAR_DATA_ATTR_INDEX]).equals(123);
|
||||||
|
chai.expect(ch[CHAR_DATA_CHAR_INDEX]).equals(NULL_CELL_CHAR);
|
||||||
|
chai.expect(ch[CHAR_DATA_WIDTH_INDEX]).equals(NULL_CELL_WIDTH);
|
||||||
|
chai.expect(ch[CHAR_DATA_CODE_INDEX]).equals(NULL_CELL_CODE);
|
||||||
|
});
|
||||||
|
});
|
||||||
+14
-9
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
|
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
import { CharData } from './Types';
|
import { CharData } from './Types';
|
||||||
@@ -11,25 +11,28 @@ import { NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR } from './Buffer';
|
|||||||
* Once the storages are in place it will proxy access to
|
* Once the storages are in place it will proxy access to
|
||||||
* typed array based line data.
|
* typed array based line data.
|
||||||
* TODO: move typical line actions in `InputHandler` and `Terminal` here:
|
* TODO: move typical line actions in `InputHandler` and `Terminal` here:
|
||||||
* - create blank line
|
* - create blank line - done
|
||||||
* - insert cells
|
* - insert cells
|
||||||
* - remove cells
|
* - remove cells
|
||||||
|
* - maybe Buffer.translateBufferLineToString
|
||||||
*/
|
*/
|
||||||
export class TerminalLine {
|
export class TerminalLine {
|
||||||
|
static defaultCell: CharData = [0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE];
|
||||||
static blankLine(cols: number, attr: number, isWrapped?: boolean): TerminalLine {
|
static blankLine(cols: number, attr: number, isWrapped?: boolean): TerminalLine {
|
||||||
const ch: CharData = [attr, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE];
|
const ch: CharData = [attr, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE];
|
||||||
const line = new TerminalLine();
|
return new TerminalLine(cols, ch, isWrapped);
|
||||||
if (isWrapped) line.isWrapped = true;
|
|
||||||
for (let i = 0; i < cols; i++) line.push(ch);
|
|
||||||
return line;
|
|
||||||
}
|
}
|
||||||
private _data: CharData[];
|
private _data: CharData[];
|
||||||
public isWrapped = false;
|
public isWrapped = false;
|
||||||
length: number;
|
length: number;
|
||||||
constructor() {
|
constructor(cols?: number, ch?: CharData, isWrapped?: boolean) {
|
||||||
this._data = [];
|
this._data = [];
|
||||||
this.length = this._data.length;
|
this.length = this._data.length;
|
||||||
|
if (cols) {
|
||||||
|
if (!ch) ch = TerminalLine.defaultCell;
|
||||||
|
for (let i = 0; i < cols; i++) this.push(ch); // Note: the ctor ch is not cloned
|
||||||
|
}
|
||||||
|
if (isWrapped) this.isWrapped = true;
|
||||||
// for debugging purpose:
|
// for debugging purpose:
|
||||||
// throw Error when something tries to do number index access
|
// throw Error when something tries to do number index access
|
||||||
// TODO: remove when done with transition
|
// TODO: remove when done with transition
|
||||||
@@ -45,7 +48,6 @@ export class TerminalLine {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
get(index: number): CharData {
|
get(index: number): CharData {
|
||||||
return this._data[index];
|
return this._data[index];
|
||||||
@@ -75,4 +77,7 @@ export class TerminalLine {
|
|||||||
release(): void {
|
release(): void {
|
||||||
// TODO: unref here
|
// TODO: unref here
|
||||||
}
|
}
|
||||||
|
toArray(): CharData[] {
|
||||||
|
return this._data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user