* Serializes terminal rows into a string that can be written back to the * terminal to restore the state. The cursor will also be positioned to the * correct cell. * * @param options Custom options to allow control over what gets serialized.
(options?: ISerializeOptions)
| 527 | * @param options Custom options to allow control over what gets serialized. |
| 528 | */ |
| 529 | public serialize(options?: ISerializeOptions): string { |
| 530 | if (!this._terminal) { |
| 531 | throw new Error("Cannot use addon until it has been loaded") |
| 532 | } |
| 533 | |
| 534 | const buffer = getTerminalBuffers(this._terminal) |
| 535 | |
| 536 | if (!buffer) { |
| 537 | return "" |
| 538 | } |
| 539 | |
| 540 | const normalBuffer = buffer.normal ?? buffer.active |
| 541 | const altBuffer = buffer.alternate |
| 542 | |
| 543 | if (!normalBuffer) { |
| 544 | return "" |
| 545 | } |
| 546 | |
| 547 | let content = options?.range |
| 548 | ? this._serializeBufferByRange(normalBuffer, options.range, true) |
| 549 | : this._serializeBufferByScrollback(normalBuffer, options?.scrollback) |
| 550 | |
| 551 | if (!options?.excludeAltBuffer && buffer.active?.type === "alternate" && altBuffer) { |
| 552 | const alternateContent = this._serializeBufferByScrollback(altBuffer, undefined) |
| 553 | content += `\u001b[?1049h\u001b[H${alternateContent}` |
| 554 | } |
| 555 | |
| 556 | return content |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * Serializes terminal content as plain text (no escape sequences) |
no test coverage detected