mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
remove pushRecycling, test case for trimAndRecycle, docs
This commit is contained in:
+7
-10
@@ -25,7 +25,7 @@ import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminalOptions
|
||||
import { IMouseZoneManager } from './ui/Types';
|
||||
import { IRenderer } from './renderer/Types';
|
||||
import { BufferSet } from './BufferSet';
|
||||
import { Buffer, MAX_BUFFER_SIZE, DEFAULT_ATTR, NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR } from './Buffer';
|
||||
import { Buffer, MAX_BUFFER_SIZE, DEFAULT_ATTR, NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR, CHAR_DATA_ATTR_INDEX } from './Buffer';
|
||||
import { CompositionHelper } from './CompositionHelper';
|
||||
import { EventEmitter } from './common/EventEmitter';
|
||||
import { Viewport } from './Viewport';
|
||||
@@ -1179,23 +1179,19 @@ 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 {
|
||||
<<<<<<< HEAD
|
||||
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);
|
||||
if (!newLine || newLine.length !== this.cols || newLine.get(0)[CHAR_DATA_ATTR_INDEX] !== this.eraseAttr()) {
|
||||
newLine = this.buffer.getBlankLine(this.eraseAttr(), isWrapped);
|
||||
this._blankLine = newLine;
|
||||
}
|
||||
newLine.isWrapped = !!(isWrapped);
|
||||
} else {
|
||||
newLine = this.buffer.getBlankLine(DEFAULT_ATTR, isWrapped);
|
||||
newLine = this.buffer.getBlankLine(this.eraseAttr(), isWrapped);
|
||||
}
|
||||
|
||||
=======
|
||||
const newLine = this.buffer.getBlankLine(this.eraseAttr(), isWrapped);
|
||||
>>>>>>> master
|
||||
const topRow = this.buffer.ybase + this.buffer.scrollTop;
|
||||
const bottomRow = this.buffer.ybase + this.buffer.scrollBottom;
|
||||
|
||||
@@ -1206,9 +1202,10 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
// Insert the line using the fastest method
|
||||
if (bottomRow === this.buffer.lines.length - 1) {
|
||||
if (useRecycling) {
|
||||
// this.buffer.lines.pushRecycling((item) => (item) ? item.copyFrom(newLine) : newLine.clone());
|
||||
if (willBufferBeTrimmed) {
|
||||
(this.buffer.lines as any).trimAndRecycle().copyFrom(newLine);
|
||||
// Warning: Never call .trimAndRecycle() without the
|
||||
// willBufferBeTrimmed guard!
|
||||
this.buffer.lines.trimAndRecycle().copyFrom(newLine);
|
||||
} else {
|
||||
this.buffer.lines.push(newLine.clone());
|
||||
}
|
||||
|
||||
@@ -257,4 +257,20 @@ describe('CircularList', () => {
|
||||
assert.equal(list.get(3), 4);
|
||||
});
|
||||
});
|
||||
describe('trimAndRecycle', function(): void {
|
||||
it('should return correct element', function(): void {
|
||||
const list = new CircularList<number[]>(5);
|
||||
list.push([0]);
|
||||
list.push([1]);
|
||||
list.push([2]);
|
||||
list.push([3]);
|
||||
list.push([4]);
|
||||
assert.equal(list.trimAndRecycle()[0], 0);
|
||||
assert.equal(list.trimAndRecycle()[0], 1);
|
||||
assert.equal(list.trimAndRecycle()[0], 2);
|
||||
assert.equal(list.trimAndRecycle()[0], 3);
|
||||
assert.equal(list.trimAndRecycle()[0], 4);
|
||||
assert.equal(list.trimAndRecycle()[0], 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -101,23 +101,14 @@ export class CircularList<T> extends EventEmitter implements ICircularList<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Recycling push variant with a callback.
|
||||
* The callback gets the value at the current position to be overwritten.
|
||||
* Return the new value from the callback.
|
||||
* Recycling trim.
|
||||
* This is used to recycle buffer lines in Terminal.scroll when
|
||||
* the list is at maxLength as a push replacement.
|
||||
* Returns the old line as new one to be recycled.
|
||||
* Note: There are no bound checks for performance reasons,
|
||||
* the method is a special optimization for Terminal.scroll,
|
||||
* do not use it anywhere else.
|
||||
*/
|
||||
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++;
|
||||
if (this._startIndex === this._maxLength) {
|
||||
this._startIndex = 0;
|
||||
}
|
||||
this.emit('trim', 1);
|
||||
} else {
|
||||
this._length++;
|
||||
}
|
||||
}
|
||||
|
||||
public trimAndRecycle(): T | undefined {
|
||||
this._startIndex = ++this._startIndex % this._maxLength;
|
||||
this.emit('trim', 1);
|
||||
|
||||
+1
-1
@@ -28,7 +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;
|
||||
trimAndRecycle(): T | undefined;
|
||||
pop(): T | undefined;
|
||||
splice(start: number, deleteCount: number, ...items: T[]): void;
|
||||
trimStart(count: number): void;
|
||||
|
||||
Reference in New Issue
Block a user