switch for BufferLineJsArray vs BufferLineTypedArray
This commit is contained in:
+38
-2
@@ -4,10 +4,10 @@
|
||||
*/
|
||||
|
||||
import { CircularList } from './common/CircularList';
|
||||
import { CharData, ITerminal, IBuffer, IBufferLine } from './Types';
|
||||
import { CharData, ITerminal, IBuffer, IBufferLine, IBufferLineConstructor } from './Types';
|
||||
import { EventEmitter } from './EventEmitter';
|
||||
import { IMarker } from 'xterm';
|
||||
import { BufferLine } from './BufferLine';
|
||||
import { BufferLine, BufferLineJsArray, BufferLineTypedArray } from './BufferLine';
|
||||
|
||||
export const DEFAULT_ATTR = (0 << 18) | (257 << 9) | (256 << 0);
|
||||
export const CHAR_DATA_ATTR_INDEX = 0;
|
||||
@@ -39,6 +39,7 @@ export class Buffer implements IBuffer {
|
||||
public savedY: number;
|
||||
public savedX: number;
|
||||
public markers: Marker[] = [];
|
||||
private _bufferLineConstructor: IBufferLineConstructor;
|
||||
|
||||
/**
|
||||
* Create a new Buffer.
|
||||
@@ -53,6 +54,40 @@ export class Buffer implements IBuffer {
|
||||
this.clear();
|
||||
}
|
||||
|
||||
public setBufferLineFactory(type: string): void {
|
||||
if (type === 'JsArray') {
|
||||
if (this._bufferLineConstructor === BufferLineJsArray) {
|
||||
return;
|
||||
}
|
||||
this._bufferLineConstructor = BufferLineJsArray;
|
||||
this._recreateLines();
|
||||
} else if (type === 'TypedArray') {
|
||||
if (this._bufferLineConstructor === BufferLineTypedArray) {
|
||||
return;
|
||||
}
|
||||
this._bufferLineConstructor = BufferLineTypedArray;
|
||||
this._recreateLines();
|
||||
} else {
|
||||
this._bufferLineConstructor = BufferLine;
|
||||
}
|
||||
}
|
||||
|
||||
private _recreateLines(): void {
|
||||
if (!this.lines) return;
|
||||
for (let i = 0; i < this.lines.length; ++i) {
|
||||
const oldLine = this.lines.get(i);
|
||||
const newLine = new this._bufferLineConstructor(oldLine.length);
|
||||
for (let j = 0; j < oldLine.length; ++j) {
|
||||
newLine.set(j, oldLine.get(j));
|
||||
}
|
||||
this.lines.set(i, newLine);
|
||||
}
|
||||
}
|
||||
|
||||
public getBlankLine(cols: number, attr: number, isWrapped?: boolean): IBufferLine {
|
||||
return this._bufferLineConstructor.blankLine(cols, attr, isWrapped);
|
||||
}
|
||||
|
||||
public get hasScrollback(): boolean {
|
||||
return this._hasScrollback && this.lines.maxLength > this._terminal.rows;
|
||||
}
|
||||
@@ -94,6 +129,7 @@ export class Buffer implements IBuffer {
|
||||
* Clears the buffer to it's initial state, discarding all previous data.
|
||||
*/
|
||||
public clear(): void {
|
||||
this.setBufferLineFactory(this._terminal.options.bufferLineConstructor);
|
||||
this.ydisp = 0;
|
||||
this.ybase = 0;
|
||||
this.y = 0;
|
||||
|
||||
Reference in New Issue
Block a user