MCPcopy Create free account
hub / github.com/anomalyco/opencode / serialize

Method serialize

packages/app/src/addons/serialize.ts:529–557  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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)

Callers 4

makeFunction · 0.80
persistTerminalFunction · 0.80
serialize.test.tsFile · 0.80

Calls 3

getTerminalBuffersFunction · 0.85

Tested by

no test coverage detected