mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1895] [CLOSED] [TUI] highlight fenced code blocks in streamed chat output #3747
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3747
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/1895
Author: @MegaRushX
Created: 10/10/2026
Status: ❌ Closed
Base:
main← Head:fix/chat-syntax-highlighting📝 Commits (1)
fa86264chat: syntax highlighting for fenced code blocks in streamed output📊 Changes
3 files changed (+219 additions, -1 deletions)
View changed files
📝
chat.py(+7 -1)➕
highlight.py(+138 -0)➕
test_highlight.py(+74 -0)📄 Description
Problem and result
chat.pyprinted streamed assistant content raw, so any fenced code block (HTML, Python, JSON, ...) landed as flat gray plain text in the terminal. After this change, lines inside a fenced code block are colored in the terminal (tags, strings, comments, keywords, numbers; one regex family per language: HTML/XML, Python, C/C++, JS/TS, shell, JSON, CSS, SQL, diff), prose passes through untouched, and a fence whose ``` marker is split across streamed chunks still opens. Only a partial last line is held back until its newline arrives; the stream stays incremental.Related discussion
none — not attached to an open issue. AI-agent contribution, unsolicited: this came from running the chat UI and reading the code. Closed in the 0.2.0-beta tracker reset (Oct 19); reopening per the process. Say the word and I stop or take it down.
Approach
New
highlight.py, standard library only, wired intochat.py's stream loop (hl.feed()per chunk,hl.flush()at the end). No dependency, no engine files touched, pure host Python, no build needed. Assistant history keeps the raw text; only the terminal display is painted. Output when stdout is not a tty stays byte-identical to the last release.Validation
Passed:
python3 test_highlight.py— 8/8 (prose unchanged with/without color, python + html blocks highlighted, fence split across chunks, partial-line hold-back, unknown-language passthrough, all bytes preserved). Environment: Linux host Python 3.12, run on 0.2.0-beta maine88ee39dwith this patch rebased locally (rebase clean, no conflicts), and on the PR headfa862640earlier.Failed:
Not run:
Limits
Languages are covered by regex families, not full grammars; nested markup inside a fenced block (markdown inside a code fence, etc.) passes through unpainted. Note on this reopen: the rebased branch could not be pushed — my token lacks the
workflowscope and the new upstream.github/workflows/intake.ymlsits in the push path, so the PR head remainsfa862640, which applies cleanly one88ee39d(verified by local rebase above).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.