more TerminalLine tests

This commit is contained in:
Jörg Breitbart
2018-08-26 19:59:16 +02:00
parent 9c68eb3b11
commit d4c621a182
3 changed files with 52 additions and 23 deletions
+12 -23
View File
@@ -10,14 +10,15 @@ import { NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR } from './Buffer';
* Currently the class is a thin proxy to `CharData[]`.
* Once the storages are in place it will proxy access to
* typed array based line data.
* TODO: move typical line actions in `InputHandler` and `Terminal` here:
* - create blank line - done
* - insert cells - done
* - remove cells - done
* - maybe Buffer.translateBufferLineToString
*
* next steps towards typed array:
* - replace all external push/pop/splice accesses
* TODO:
* - move Buffer.translateBufferLineToString here?
* - next steps towards typed array:
* - create ITerminalLine interface w'o length methods
* - resize method
* - replace all external push/pop/splice accesses
* - fixed length
* - remove push/pop/splice
* - implement typed array alternative once string is removed from CharData
*/
export class TerminalLine {
static defaultCell: CharData = [0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE];
@@ -36,21 +37,6 @@ export class TerminalLine {
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:
// throw Error when something tries to do number index access
// TODO: remove when done with transition
/*
for (let i = 0; i < 100; ++i) {
Object.defineProperty(this, i.toString(), {
get: () => {
throw new Error('get per index access is disabled');
},
set: (value: any) => {
throw new Error('set per index access is disabled');
}
});
}
*/
}
get(index: number): CharData {
return this._data[index];
@@ -59,17 +45,20 @@ export class TerminalLine {
this._data[index] = data;
// TODO: unref old, ref new
}
// to be removed for typed array
pop(): CharData | undefined {
// TODO: unref here, change CharData to [typeof Attributes, ...]
const data = this._data.pop();
this.length = this._data.length;
return data;
}
// to be removed for typed array
push(data: CharData): void {
this._data.push(data);
this.length = this._data.length;
// TODO: ref here
}
// to be removed for typed array
splice(start: number, deleteCount: number, ...items: CharData[]): CharData[] {
const removed = this._data.splice(start, deleteCount, ...items);
this.length = this._data.length;