mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Move the test util to static method
This commit is contained in:
@@ -330,7 +330,28 @@ export class SerializeAddon implements ITerminalAddon {
|
||||
return result;
|
||||
}
|
||||
|
||||
public inspectBuffer(buffer: IBuffer): { x: number, y: number, data: any[][] } {
|
||||
public serialize(scrollback?: number, options: ISerializeOptions = {}): string {
|
||||
// TODO: Add word wrap mode support
|
||||
// TODO: Add combinedData support
|
||||
if (!this._terminal) {
|
||||
throw new Error('Cannot use addon until it has been loaded');
|
||||
}
|
||||
|
||||
if (this._terminal.buffer.active.type === 'normal' || !(options.withAlternate ?? true)) {
|
||||
return this._getString(this._terminal.buffer.active, scrollback, options);
|
||||
}
|
||||
|
||||
const normalScreenContent = this._getString(this._terminal.buffer.normal, scrollback, options);
|
||||
// alt screen don't have scrollback
|
||||
const alternativeScreenContent = this._getString(this._terminal.buffer.alternate, undefined, options);
|
||||
|
||||
return normalScreenContent
|
||||
+ '\u001b[?1049h\u001b[H'
|
||||
+ alternativeScreenContent;
|
||||
}
|
||||
|
||||
// this is a util used only for test
|
||||
private static _inspectBuffer(buffer: IBuffer): { x: number, y: number, data: any[][] } {
|
||||
const lines: any[] = [];
|
||||
const cell = buffer.getNullCell();
|
||||
|
||||
@@ -367,25 +388,5 @@ export class SerializeAddon implements ITerminalAddon {
|
||||
};
|
||||
}
|
||||
|
||||
public serialize(scrollback?: number, options: ISerializeOptions = {}): string {
|
||||
// TODO: Add word wrap mode support
|
||||
// TODO: Add combinedData support
|
||||
if (!this._terminal) {
|
||||
throw new Error('Cannot use addon until it has been loaded');
|
||||
}
|
||||
|
||||
if (this._terminal.buffer.active.type === 'normal' || !(options.withAlternate ?? true)) {
|
||||
return this._getString(this._terminal.buffer.active, scrollback, options);
|
||||
}
|
||||
|
||||
const normalScreenContent = this._getString(this._terminal.buffer.normal, scrollback, options);
|
||||
// alt screen don't have scrollback
|
||||
const alternativeScreenContent = this._getString(this._terminal.buffer.alternate, undefined, options);
|
||||
|
||||
return normalScreenContent
|
||||
+ '\u001b[?1049h\u001b[H'
|
||||
+ alternativeScreenContent;
|
||||
}
|
||||
|
||||
public dispose(): void { }
|
||||
}
|
||||
|
||||
@@ -342,11 +342,12 @@ describe('SerializeAddon', () => {
|
||||
];
|
||||
|
||||
await writeSync(page, lines.join('\\r\\n'));
|
||||
const originalBuffer = await page.evaluate(`serializeAddon.inspectBuffer(term.buffer.normal);`);
|
||||
const originalBuffer = await page.evaluate(`SerializeAddon._inspectBuffer(term.buffer.normal);`);
|
||||
|
||||
const result = await page.evaluate(`serializeAddon.serialize(undefined, { withAlternate: true, withCursor: true });`);
|
||||
|
||||
await writeSync(page, '\' +' + JSON.stringify('\x1bc' + result) + '+ \'');
|
||||
const newBuffer = await page.evaluate(`serializeAddon.inspectBuffer(term.buffer.normal);`);
|
||||
const newBuffer = await page.evaluate(`SerializeAddon._inspectBuffer(term.buffer.normal);`);
|
||||
|
||||
assert.deepEqual(originalBuffer, newBuffer);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user