fix: persist VT stream parser state across writes#63
Merged
Conversation
Contributor
sreya
commented
Nov 25, 2025
- Also updates the demo to use 'ws' instead of rolling our own implementation
This fixes tab completion corruption on macOS (and likely other platforms) when escape sequences are split across WebSocket message boundaries. Root cause: Each call to write() was creating a new VT parser stream, which lost parser state between calls. When zsh sends cursor positioning sequences like ESC[9A (cursor up 9 lines), they could be split as: - Message 1: '...\x1b[9' - Message 2: 'A...' The parser would see '\x1b[9' as incomplete, then 'A' as a literal character. Fix: Store the VT stream in TerminalWrapper and reuse it across writes, so incomplete escape sequences are properly buffered and parsed when the remaining bytes arrive. Changes to WASM patch: - Add 'stream: ReadonlyStream' field to TerminalWrapper - Initialize stream once in newWithConfig() after terminal creation - Reuse wrapper.stream in write() instead of creating new stream - Call stream.deinit() in free()
Removed ~115 lines of hand-rolled WebSocket frame parsing code in favor of the battle-tested ws package. This simplifies the codebase and ensures proper WebSocket protocol handling. Changes: - Add ws@8.18.0 dependency - Replace manual WebSocket handshake and frame parsing with WebSocketServer - Simplify PTY<->WebSocket data flow using ws.send() instead of sendWebSocketFrame() - Remove crypto import (was only used for WebSocket handshake)
The patch file had incorrect metadata (604 lines vs actual 611 lines) which could cause git apply to fail or truncate the file. Regenerated the patch cleanly from the modified ghostty submodule.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.