Merge pull request #5436 from xtermjs/merogge/serialize-range

add range to IHTMLSerializeOptions
This commit is contained in:
Daniel Imms
2025-10-28 09:41:17 -07:00
committed by GitHub
3 changed files with 34 additions and 0 deletions
@@ -148,6 +148,22 @@ describe('SerializeAddon', () => {
assert.equal((output.match(/<div><span>&lt;a>&amp;pi;<\/span><\/div>/g) || []).length, 1, output);
});
it('serializes rows within a provided range', async () => {
await writeP(terminal, 'bye hello\r\nworld');
const output = serializeAddon.serializeAsHTML({
range: {
startLine: 0,
endLine: 0,
startCol: 4
}
});
const rowMatches = output.match(/<div><span>.*?<\/span><\/div>/g) || [];
assert.equal(rowMatches.length, 1, output);
assert.ok(rowMatches[0]?.includes('hello'));
assert.ok(!output.includes('bye'));
assert.ok(!output.includes('world'));
});
it('cells with bold styling', async () => {
await writeP(terminal, ' ' + sgr('1') + 'terminal' + sgr('22') + ' ');
@@ -450,6 +450,13 @@ export class SerializeAddon implements ITerminalAddon , ISerializeApi {
const buffer = terminal.buffer.active;
const handler = new HTMLSerializeHandler(buffer, terminal, options);
const onlySelection = options.onlySelection ?? false;
const range = options.range;
if (range) {
return handler.serialize({
start: { x: range.startCol, y: typeof range.startLine === 'number' ? range.startLine : range.startLine },
end: { x: terminal.cols, y: typeof range.endLine === 'number' ? range.endLine : range.endLine }
});
}
if (!onlySelection) {
const maxRows = buffer.length;
const scrollback = options.scrollback;
+11
View File
@@ -90,6 +90,17 @@ declare module '@xterm/addon-serialize' {
* Whether to include the global background of the terminal. False by default.
*/
includeGlobalBackground: boolean;
/**
* The range to serialize. This is prioritized over {@link onlySelection}.
*/
range?: ISerializeBufferRange;
}
export interface ISerializeBufferRange {
startLine: number;
endLine: number;
startCol: number;
}
export interface ISerializeRange {