feat(tui): highlight fenced code with terminal theme colors - #261
Merged
Merged
Conversation
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.
Summary
Add syntax highlighting to TUI code fences, including TypeScript and TSX, using Syntect and Two-face. Syntax scopes map to Kit鈥檚 existing terminal palette rather than a bundled RGB theme; wrapping and source-copy ranges are preserved.
Impact
Unknown or explicitly plain-text languages retain the existing code style. Highlighting falls back to plain text for the remainder of a fence after a parser error or input limit: 4 KiB per line and 128 KiB of parsed code per document render. These are input limits, not a regex execution-time guarantee.
Technical details
Minimal TUI-only dependencies
Pin Syntect 5.3.0 and Two-face 0.5.2 with the pure-Rust fancy-regex backend. Do not enable Syntect鈥檚 bundled syntaxes/themes, HTML, YAML/plist loaders, or Oniguruma; only Two-face鈥檚 newline-aware syntax bundle is used. Headless builds exclude the added dependency versions.
The lockfile adds four package versions without upgrades, including fancy-regex 0.16.2 alongside the existing version and bincode 1.3.3. Bincode has an unmaintained advisory (RUSTSEC-2025-0141), not a reported vulnerability; this integration uses it only for compiled-in grammar data. Published archives and packaged sources were reconciled against registry checksums and upstream commits, with Two-face鈥檚 embedded payloads matched to upstream LFS hashes.
Fence-local parsing
Load the grammar set lazily and retain multiline parsing state within each fence. Streaming suffix rerenders reconstruct that state through the existing transcript cache path. Once parsing is skipped or fails, do not resume that fence with stale state.