* Internal write implementation (extracted from write())
(data: string | Uint8Array, callback?: () => void)
| 532 | * Internal write implementation (extracted from write()) |
| 533 | */ |
| 534 | private writeInternal(data: string | Uint8Array, callback?: () => void): void { |
| 535 | // Note: We intentionally do NOT clear selection on write - most modern terminals |
| 536 | // preserve selection when new data arrives. Selection is cleared by user actions |
| 537 | // like clicking or typing, not by incoming data. |
| 538 | |
| 539 | // Write directly to WASM terminal (handles VT parsing internally) |
| 540 | this.wasmTerm!.write(data); |
| 541 | |
| 542 | // Process any responses generated by the terminal (e.g., DSR cursor position) |
| 543 | // These need to be sent back to the PTY via onData |
| 544 | this.processTerminalResponses(); |
| 545 | |
| 546 | // Check for bell character (BEL, \x07) |
| 547 | // WASM doesn't expose bell events, so we detect it in the data stream |
| 548 | if (typeof data === 'string' && data.includes('\x07')) { |
| 549 | this.bellEmitter.fire(); |
| 550 | } else if (data instanceof Uint8Array && data.includes(0x07)) { |
| 551 | this.bellEmitter.fire(); |
| 552 | } |
| 553 | |
| 554 | // Invalidate link cache (content changed) |
| 555 | this.linkDetector?.invalidateCache(); |
| 556 | |
| 557 | // Phase 2: Auto-scroll to bottom on new output (xterm.js behavior) |
| 558 | if (this.viewportY !== 0) { |
| 559 | this.scrollToBottom(); |
| 560 | } |
| 561 | |
| 562 | // Check for title changes (OSC 0, 1, 2 sequences) |
| 563 | // This is a simplified implementation - Ghostty WASM may provide this |
| 564 | if (typeof data === 'string' && data.includes('\x1b]')) { |
| 565 | this.checkForTitleChange(data); |
| 566 | } |
| 567 | |
| 568 | // Call callback if provided |
| 569 | if (callback) { |
| 570 | // Queue callback after next render |
| 571 | requestAnimationFrame(callback); |
| 572 | } |
| 573 | |
| 574 | // Render will happen on next animation frame |
| 575 | } |
| 576 | |
| 577 | /** |
| 578 | * Write data with newline |
no test coverage detected