better integration and experimentalPushRecycling option

This commit is contained in:
Jörg Breitbart
2018-10-10 15:00:38 +02:00
parent 33a358033c
commit 751e2efa75
5 changed files with 29 additions and 12 deletions
+24 -10
View File
@@ -106,7 +106,8 @@ const DEFAULT_OPTIONS: ITerminalOptions = {
theme: null,
rightClickSelectsWord: Browser.isMac,
rendererType: 'canvas',
experimentalBufferLineImpl: 'JsArray'
experimentalBufferLineImpl: 'JsArray',
experimentalPushRecycling: false
};
export class Terminal extends EventEmitter implements ITerminal, IDisposable, IInputHandlingTerminal {
@@ -208,6 +209,9 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
private _screenDprMonitor: ScreenDprMonitor;
private _theme: ITheme;
// bufferline to clone/copy from for new blank lines
private _blankLine: IBufferLine = null;
public cols: number;
public rows: number;
@@ -496,6 +500,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
case 'experimentalBufferLineImpl':
this.buffers.normal.setBufferLineFactory(value);
this.buffers.alt.setBufferLineFactory(value);
this._blankLine = null;
break;
}
// Inform renderer of changes
@@ -1174,13 +1179,18 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
* @param isWrapped Whether the new line is wrapped from the previous line.
*/
public scroll(isWrapped?: boolean): void {
// TODO: make blank a member
let blank: IBufferLine = (this as any)._blank;
if (!blank || blank.length !== this.cols) {
blank = this.buffer.getBlankLine(DEFAULT_ATTR, isWrapped);
(this as any)._blank = blank;
let newLine: IBufferLine;
const useRecycling = this.options.experimentalPushRecycling;
if (useRecycling) {
newLine = this._blankLine;
if (!newLine || newLine.length !== this.cols) {
newLine = this.buffer.getBlankLine(DEFAULT_ATTR, isWrapped);
this._blankLine = newLine;
}
newLine.isWrapped = !!(isWrapped);
} else {
newLine = this.buffer.getBlankLine(DEFAULT_ATTR, isWrapped);
}
blank.isWrapped = !!(isWrapped);
const topRow = this.buffer.ybase + this.buffer.scrollTop;
const bottomRow = this.buffer.ybase + this.buffer.scrollBottom;
@@ -1191,9 +1201,13 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
// Insert the line using the fastest method
if (bottomRow === this.buffer.lines.length - 1) {
(this.buffer.lines as any).pushRecycling((line: IBufferLine | undefined) => (line) ? line.copyFrom(blank) : blank.clone());
if (useRecycling) {
this.buffer.lines.pushRecycling((item) => (item) ? item.copyFrom(newLine) : newLine.clone());
} else {
this.buffer.lines.push(newLine);
}
} else {
this.buffer.lines.splice(bottomRow + 1, 0, blank.clone());
this.buffer.lines.splice(bottomRow + 1, 0, (useRecycling) ? newLine.clone() : newLine);
}
// Only adjust ybase and ydisp when the buffer is not trimmed
@@ -1215,7 +1229,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
// scrollback, instead we can just shift them in-place.
const scrollRegionHeight = bottomRow - topRow + 1/*as it's zero-based*/;
this.buffer.lines.shiftElements(topRow + 1, scrollRegionHeight - 1, -1);
this.buffer.lines.set(bottomRow, blank.clone());
this.buffer.lines.set(bottomRow, (useRecycling) ? newLine.clone() : newLine);
}
// Move the viewport to the bottom of the buffer unless the user is
+1 -1
View File
@@ -522,7 +522,7 @@ export interface IBufferLine {
replaceCells(start: number, end: number, fill: CharData): void;
resize(cols: number, fill: CharData, shrink?: boolean): void;
fill(fillCharData: CharData): void;
copyFrom(line: IBufferLine): void;
copyFrom(line: IBufferLine): IBufferLine;
clone(): IBufferLine;
}
+1 -1
View File
@@ -105,7 +105,7 @@ export class CircularList<T> extends EventEmitter implements ICircularList<T> {
* The callback gets the value at the current position to be overwritten.
* Return the new value from the callback.
*/
public pushRecycling(callback: (el: T | undefined) => T): void {
public pushRecycling(callback: (item: T | undefined) => T): void {
this._array[this._getCyclicIndex(this._length)] = callback(this._array[this._getCyclicIndex(this._length)]);
if (this._length === this._maxLength) {
this._startIndex++;
+1
View File
@@ -28,6 +28,7 @@ export interface ICircularList<T> extends IEventEmitter {
get(index: number): T | undefined;
set(index: number, value: T): void;
push(value: T): void;
pushRecycling(callback: (item: T | undefined) => T): void;
pop(): T | undefined;
splice(start: number, deleteCount: number, ...items: T[]): void;
trimStart(count: number): void;
+2
View File
@@ -112,6 +112,8 @@ declare module 'xterm' {
*/
experimentalBufferLineImpl?: 'JsArray' | 'TypedArray';
experimentalPushRecycling?: boolean;
/**
* The font size used to render text.
*/