mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
add range to IHTMLSerializeOptions
This commit is contained in:
@@ -148,6 +148,21 @@ describe('SerializeAddon', () => {
|
||||
assert.equal((output.match(/<div><span><a>&pi;<\/span><\/div>/g) || []).length, 1, output);
|
||||
});
|
||||
|
||||
it('serializes rows within a provided range', async () => {
|
||||
await writeP(terminal, 'hello\r\nworld');
|
||||
|
||||
const output = serializeAddon.serializeAsHTML({
|
||||
range: {
|
||||
start: 0,
|
||||
end: 0
|
||||
}
|
||||
});
|
||||
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('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: 0, y: typeof range.start === 'number' ? range.start : range.start.line },
|
||||
end: { x: terminal.cols, y: typeof range.end === 'number' ? range.end : range.end.line }
|
||||
});
|
||||
}
|
||||
if (!onlySelection) {
|
||||
const maxRows = buffer.length;
|
||||
const scrollback = options.scrollback;
|
||||
|
||||
@@ -90,6 +90,11 @@ declare module '@xterm/addon-serialize' {
|
||||
* Whether to include the global background of the terminal. False by default.
|
||||
*/
|
||||
includeGlobalBackground: boolean;
|
||||
|
||||
/**
|
||||
* The row range to serialize. This is prioritized over {@link onlySelection}.
|
||||
*/
|
||||
range?: ISerializeRange;
|
||||
}
|
||||
|
||||
export interface ISerializeRange {
|
||||
|
||||
Reference in New Issue
Block a user