Repository navigation
Styled text spans: more than one colour per line - #65
Merged
Merged
Conversation
Closes #60 for TypeScript. drawText applied a single Style to the whole string, so anything needing two colours on one line had to be split into separate widgets at hand-computed columns. That ruled out syntax highlighting, inline log level colouring, diffs and search-match highlighting. Adds Span/SpanLine/RichText plus span-aware measuring, truncation, padding and word wrap, a Surface.spans renderer, and RichText acceptance on drawText and ui.text/label/heading. A bare string is the one-span case, so every existing call site is untouched. The span layout is held to the exact output of the string functions it mirrors: richtext.test.ts asserts truncateSpans/fitSpans/wrapSpans agree with truncate/fit/wrap column for column across a corpus of CJK, emoji, ZWJ sequences, combining marks and overlong tokens. That parity test earned its keep immediately -- it caught wrapSpans not trimming its final line, which wrap does. The plain-string path in drawText is deliberately left intact rather than routed through the span code. The two agree, but "agree" and "emit identical cells" are different claims and every committed fixture depends on the second. Both fixture generators confirm it: no drift in ports/conformance or in the 120 demo-parity cases. 232 tests pass under Bun and Node. The six ports do not have spans yet. This is additive and changes no existing frame, so they stay in parity; porting is the remaining work on #60. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_017Df2FNu5DhinMV2soRz3cy
Merged
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.
Closes #60 for TypeScript. The six ports are follow-up work — see the last section.
What was wrong
drawTextapplied oneStyleto the whole string:so two colours on one line meant splitting into separate widgets at hand-computed columns. Syntax highlighting, inline log-level colouring, diffs and search-match highlighting were all off the table.
What this adds
Span→SpanLine→RichText, plus span-aware measuring, truncation, padding and word wrap in a newpackages/hqtui/src/richtext.ts; aSurface.spans()renderer; andRichTextacceptance ondrawTextandui.text/ui.label/ui.heading.A bare string is the one-span case, so no existing call site changes. Spans inherit the widget's style for anything they don't set, which is why
ui.label([{ text: "muted" }, { text: "red", fg: RED }])keeps the label colour on the first span.Why you can trust the layout
Two text layout engines that disagree by one column is a bug you find in a screenshot six months later. So the span versions are held to the exact output of the string versions they mirror —
richtext.test.tsassertstruncateSpans/fitSpans/wrapSpansmatchtruncate/fit/wrapcolumn for column across a corpus of CJK, emoji, ZWJ family sequences, combining marks, leading/trailing whitespace, blank lines and overlong unbroken tokens, at eight widths.That test earned its keep on the first run: it caught
wrapSpansnot trimming its final line, whichwrapdoes. That would have shipped as one stray trailing space per wrapped paragraph.Why no existing frame moves
The plain-string path inside
drawTextis deliberately left intact rather than routed through the span code. The two agree, but agree and emit identical cells are different claims, and every committed fixture depends on the second one.Both generators confirm it, with no drift:
bun ports/conformance/generate.tsbun apps/demo/scripts/native-parity.ts— 120 casesChecks
bun testandbun run test:node(was 208; +24 here)bun run typecheckcleanNot in this PR
ports/{rust,go,python,zig,cpp}and the COBOL adapter stay in parity — they simply don't offer spans yet. Porting is the rest of Styled text spans: more than one colour per line #60, and the parity corpus above is the spec to port against.string. Those are the next increment now that the core exists, and they are what a JSON response inspector or a diff view actually needs.🤖 Generated with Claude Code
https://claude.ai/code/session_017Df2FNu5DhinMV2soRz3cy