MCPcopy
hub / github.com/xtermjs/xterm.js / SerializeAddon

Class SerializeAddon

addons/addon-serialize/src/SerializeAddon.ts:425–547  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

423}
424
425export class SerializeAddon implements ITerminalAddon , ISerializeApi {
426 private _terminal: Terminal | undefined;
427
428 public activate(terminal: Terminal): void {
429 this._terminal = terminal;
430 }
431
432 private _serializeBufferByScrollback(terminal: Terminal, buffer: IBuffer, scrollback?: number): string {
433 const maxRows = buffer.length;
434 const correctRows = (scrollback === undefined) ? maxRows : constrain(scrollback + terminal.rows, 0, maxRows);
435 return this._serializeBufferByRange(terminal, buffer, {
436 start: maxRows - correctRows,
437 end: maxRows - 1
438 }, false);
439 }
440
441 private _serializeBufferByRange(terminal: Terminal, buffer: IBuffer, range: ISerializeRange, excludeFinalCursorPosition: boolean): string {
442 const handler = new StringSerializeHandler(buffer, terminal);
443 return handler.serialize({
444 start: { x: 0, y: typeof range.start === 'number' ? range.start : range.start.line },
445 end: { x: terminal.cols, y: typeof range.end === 'number' ? range.end : range.end.line }
446 }, excludeFinalCursorPosition);
447 }
448
449 private _serializeBufferAsHTML(terminal: Terminal, options: Partial<IHTMLSerializeOptions>): string {
450 const buffer = terminal.buffer.active;
451 const handler = new HTMLSerializeHandler(buffer, terminal, options);
452 const onlySelection = options.onlySelection ?? false;
453 const range = options.range;
454 if (range) {
455 return handler.serialize({
456 start: { x: range.startCol, y: typeof range.startLine === 'number' ? range.startLine : range.startLine },
457 end: { x: terminal.cols, y: typeof range.endLine === 'number' ? range.endLine : range.endLine }
458 });
459 }
460 if (!onlySelection) {
461 const maxRows = buffer.length;
462 const scrollback = options.scrollback;
463 const correctRows = (scrollback === undefined) ? maxRows : constrain(scrollback + terminal.rows, 0, maxRows);
464 return handler.serialize({
465 start: { x: 0, y: maxRows - correctRows },
466 end: { x: terminal.cols, y: maxRows - 1 }
467 });
468 }
469
470 const selection = this._terminal?.getSelectionPosition();
471 if (selection !== undefined) {
472 return handler.serialize({
473 start: { x: selection.start.x, y: selection.start.y },
474 end: { x: selection.end.x, y: selection.end.y }
475 });
476 }
477
478 return '';
479 }
480
481 private _serializeModes(terminal: Terminal): string {
482 let content = '';

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected