fix: preserve split UTF-8 across PersistentTerminal feed() calls#9
Merged
remorses merged 2 commits intoremorses:mainfrom Mar 6, 2026
Merged
fix: preserve split UTF-8 across PersistentTerminal feed() calls#9remorses merged 2 commits intoremorses:mainfrom
remorses merged 2 commits intoremorses:mainfrom
Conversation
- use a persistent TextDecoder in streaming mode for Buffer/Uint8Array input - share binary UTF-8 decoding across ptyToJson, ptyToText, and ptyToHtml - accept Uint8Array in ghostty-terminal ansi/feed typings - add regression tests for split multibyte chunk feeds
Owner
|
is there a way to remove hasBinaryDecoderState state and use the decoder directly? cc @codex review |
Contributor
Author
Yes, it's an optimization. We could swap it out for simpler logic as follows -- it just means some extra I can either push this update, or add comments to the existing PR so it's clearer what's happening, just lmk. :) |
Owner
|
Yeah I like this one better. I will publish after you push this commit |
- remove _hasBinaryDecoderState bookkeeping - recreate the streaming TextDecoder on string feeds, reset, and destroy - add a regression test for binary-to-string feed boundaries
fcc9405 to
6262592
Compare
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.
When reading from a PTY, byte chunks arrive at arbitrary boundaries. Multi-byte UTF-8 characters (emoji = 4 bytes, CJK = 3 bytes, accented chars = 2+ bytes) can be split across consecutive read() calls. The old code in PersistentTerminal.feed():
Both of these treat each chunk as a complete, self-contained UTF-8 sequence. When a multi-byte character is split (e.g., the first 2 bytes of a 4-byte emoji in one call, the remaining 2 in the next), each independent decode produces U+FFFD replacement characters (�) instead of the intended character.