mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
new approach
This commit is contained in:
+5
-6
@@ -94,13 +94,11 @@ export class BufferLine implements IBufferLine {
|
||||
}
|
||||
}
|
||||
|
||||
public copyFrom(line: IBufferLine): void {
|
||||
this._data = [];
|
||||
for (let i = 0; i < line.length; ++i) {
|
||||
this._push(line.get(i));
|
||||
}
|
||||
public copyFrom(line: BufferLine): IBufferLine {
|
||||
this._data = line._data.slice(0);
|
||||
this.length = line.length;
|
||||
this.isWrapped = line.isWrapped;
|
||||
return this;
|
||||
}
|
||||
|
||||
public clone(): IBufferLine {
|
||||
@@ -249,7 +247,7 @@ export class BufferLineTypedArray implements IBufferLine {
|
||||
}
|
||||
|
||||
/** alter to a full copy of line */
|
||||
public copyFrom(line: BufferLineTypedArray): void {
|
||||
public copyFrom(line: BufferLineTypedArray): IBufferLine {
|
||||
if (this.length !== line.length) {
|
||||
this._data = new Uint32Array(line._data);
|
||||
} else {
|
||||
@@ -262,6 +260,7 @@ export class BufferLineTypedArray implements IBufferLine {
|
||||
this._combined[el] = line._combined[el];
|
||||
}
|
||||
this.isWrapped = line.isWrapped;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** create a new clone */
|
||||
|
||||
+12
-5
@@ -21,7 +21,7 @@
|
||||
* http://linux.die.net/man/7/urxvt
|
||||
*/
|
||||
|
||||
import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminalOptions, ITerminal, IBrowser, ILinkifier, ILinkMatcherOptions, CustomKeyEventHandler, LinkMatcherHandler, CharData, CharacterJoinerHandler } from './Types';
|
||||
import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminalOptions, ITerminal, IBrowser, ILinkifier, ILinkMatcherOptions, CustomKeyEventHandler, LinkMatcherHandler, CharData, CharacterJoinerHandler, IBufferLine } from './Types';
|
||||
import { IMouseZoneManager } from './ui/Types';
|
||||
import { IRenderer } from './renderer/Types';
|
||||
import { BufferSet } from './BufferSet';
|
||||
@@ -1174,7 +1174,14 @@ 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 {
|
||||
const newLine = this.buffer.getBlankLine(DEFAULT_ATTR, isWrapped);
|
||||
// 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;
|
||||
}
|
||||
blank.isWrapped = !!(isWrapped);
|
||||
|
||||
const topRow = this.buffer.ybase + this.buffer.scrollTop;
|
||||
const bottomRow = this.buffer.ybase + this.buffer.scrollBottom;
|
||||
|
||||
@@ -1184,9 +1191,9 @@ 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.push(newLine);
|
||||
(this.buffer.lines as any).pushRecycling((line: IBufferLine | undefined) => (line) ? line.copyFrom(blank) : blank.clone());
|
||||
} else {
|
||||
this.buffer.lines.splice(bottomRow + 1, 0, newLine);
|
||||
this.buffer.lines.splice(bottomRow + 1, 0, blank.clone());
|
||||
}
|
||||
|
||||
// Only adjust ybase and ydisp when the buffer is not trimmed
|
||||
@@ -1208,7 +1215,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, newLine);
|
||||
this.buffer.lines.set(bottomRow, blank.clone());
|
||||
}
|
||||
|
||||
// Move the viewport to the bottom of the buffer unless the user is
|
||||
|
||||
@@ -100,6 +100,24 @@ 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.
|
||||
*/
|
||||
public pushRecycling(callback: (el: 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++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes and returns the last value on the list.
|
||||
* @return The popped value.
|
||||
|
||||
Reference in New Issue
Block a user