Repository navigation
[CTX-1609] feat(term): authoritative grapheme clusters and East Asian width - #2738
Conversation
… prepends safely
Second review of the grapheme rework (bitty#1767); rebased onto the merged
first round (bitty#2734), so this commit is the follow-up only.
Render (must-fix 1):
- A paint group with more than one shaped member is one committed layout
unit; its entries advance inside that unit (`कि`: 4.16 px + 13.81 px for
one cell), so the per-cell advance gate must not read them as a cell
advance. The gate now skips multi-member groups, and entries sharing a
byte offset are excluded from the median that serves as its reference.
Deterministic FakeShaper cases (`कि`, `क्ष`, a flag pair without a
ligature, a ZWJ family, a wide ambiguous scalar) pin every member painting
without host fonts.
- The gate measures the shaper's own (narrow) cell count, so a wide East
Asian ambiguous cluster stays shaped under
`terminal.ambiguous_width = "wide"` instead of degrading because the
policy span is two cells.
Terminal truth (must-fix 2):
- `restore_scrollback_text` selects the first non-zero-width scalar as
`Cell::glyph`, so a leading `Prepend` (`"\u{0600}1"`) can no longer hide
its base. Leading zero-width scalars attach to the preceding cell's tail
(stepping back over a wide spacer) exactly like `print`, and a
line-leading one is dropped.
- Tail overflow mirrors print: zero-width scalars past the bound drop, a
printable scalar starts a fresh cell instead of truncating the line.
- Restore tests cover `"\u{0600}1"`, `"a\u{0600}1"`, and a nine-scalar
printable cluster.
Follow-ups:
- The generated UAX #29 tables now carry the full
`Grapheme_Cluster_Break=Control` class (19 ranges, 3893 scalars),
replacing the curated GB4/GB5 list that missed soft hyphen, the Mongolian
vowel separator, the bidi isolates, the interlinear/musical/shorthand and
Egyptian format scalars, and the tag-plane ranges. CR/LF stay included
explicitly per GB4/GB5. The measured over-join cases are pinned.
- `InCB=Linker` doc count corrected to 23.
- The generator formats its output with the pinned `rustfmt`, so regeneration
is byte-identical without a manual `cargo fmt` step.
- The prepend test documents that only a first-row lead is dropped; a
later-row lead attaches to the previous row's last cell.
- Drive-by: two pre-existing private intra-doc links broke the rustdoc gate on
main (`SwashSingle` -> `system_db`, `commit_profile_rename` ->
`PROFILE_RENAME_OVERRIDE`). Both are code spans now; the identical one-line
fixes ride in #2737, so on a rebase after it lands these hunks are no-ops.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 48 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Xuepoo
left a comment
There was a problem hiding this comment.
PR-2738 REVIEWER VERDICT: APPROVE
Attribution: independent reviewer subagent (Bitty blitz guard tick, 2026-10-27). Verification on scratch clone of head 5301f3e (10-file diff); verdict follows.
Verified:
- Multi-glyph cluster gating (
multi_member_entriesinshaped.rs): linear equal-offset grouping,max(1)guards division,is_finite()guardsper_cell_advance; no recursion/panic paths; safe to unsorted input (false negative only). restore_scrollback_textre-prepend loop bounded bycells.len() < width,checked_subtargets, spacer-precedes-cell invariant, labeled'linebreak on wide truncation.- Tests:
bitty-rendergrid lib tests 122 passed/0 failed; new CTX-1609 shaped-cluster tests all pass; shaped_clusters_paint integration (5/5, incl.shaping_misaligned == 0);bitty-term-state13 suites 0-failed incl. newgrapheme_clusters_1609restore tests and unicode table invariants. - Per-run
Vec<bool>allocation in the shaped path is consistent with existing per-run allocations; informational. cargo check -p bitty-render -p bitty-term-stateclean; no let-chains; no hardcoded host/env values.
Non-blocking findings:
multi_member_entriesallocates per call in the render path (matches existing style; optional fold-in).- Byte-offset sortedness of shaper output is an unstated precondition (harmless).
CI at review time: 12 pass / 3 pending / 0 fail on head. Head sha at verdict: 5301f3e520d4d63be2f4f54c6ad51c300acf941e. CTX label note: PR title carries [CTX-1609] (guard context said CTX-1610 — label mismatch in the guard prompt only).
Priority: P1 | Area: term | Labels: feat,P1,area:term | Milestone: v0.3.0 | RFC: OQ-090 | Task: CTX-1609
Summary
Ships #1767 (OQ-090): an extended grapheme cluster is the layout unit, East
Asian Ambiguous width is configurable, and every UAX #29/UAX #11 property the
print and paint paths read is generated from pinned UCD 18.0.0 snapshots.
The first round merged as #2734. This branch was rebased onto
main(
f75d8eb7) and carries the follow-ups from the two review rounds on top ofit (10 files, no overlap with #2736/#2737).
What lands
UCD tables and generator provenance
scripts/generate-unicode-tables.pyemits the checked-incrates/bitty-term-state/src/unicode_tables.rsfrom four pinned inputs, witha SHA-256 digest per input in the module header and the Unicode License v3
notice:
East_Asian_Width(UAX #11)Extended_Pictographic(UTS #51)Grapheme_Cluster_Break=Control(GB4/GB5)Grapheme_Cluster_Break=Extend(GB9)Grapheme_Cluster_Break=SpacingMark(GB9a)Grapheme_Cluster_Break=Prepend(GB9b)InCB=Linker(GB9c)InCB=Consonant(GB9c)InCB=Extend(GB9c)No curated subsets remain: GB4/GB5 previously missed soft hyphen, the
Mongolian vowel separator, the bidi isolates, the interlinear/musical/
shorthand and Egyptian format scalars, and the tag-plane ranges, which let
control + markover-join. GB9c follows the Unicode 18.0.0 rule shape(
InCB=Linker InCB=Extend* × InCB=Consonant), soक्१and virama+ZWNJ breakwhile real conjuncts join. The generator runs the pinned
rustfmton itsoutput, so regeneration is byte-identical without a manual format step.
terminal.ambiguous_widthterminal.ambiguous_width = "narrow" | "wide"(defaultnarrow) flowsLua -> plan -> merge -> effective -> runtime -> terminal state and the
renderer's span math, is fail-closed at every layer, appears in
inspect config/the profile schema, and is classified restart-requiredbecause committed
Cell::widthvalues cannot be re-measured live.Clusters as one cell
The print path charges an extended grapheme cluster to one leading cell
(plus a spacer for wide clusters) and stores the tail in the bounded
Cell::zerowidthbuffer: ZWJ families, flags, skin tones, keycaps, VS16emoji, decomposed Hangul, Indic conjuncts, and spacing marks stay one layout
unit for cursor movement, backspace, selection, copy, and search. Every
Prependscalar is zero-width through the same generated table GB9b reads,so a prepend can no longer hide the base it joins to.
restore_scrollback_textSession restore now selects the first non-zero-width scalar as
Cell::glyph,attaches leading zero-width scalars to the preceding cell's tail (stepping
back over a wide spacer, like
print), and mirrors print's tail-overflowpolicy: a printable scalar past
MAX_CLUSTER_SCALARSstarts a fresh cellinstead of being truncated. Tests cover
"\u{0600}1","a\u{0600}1", and anine-scalar printable cluster.
Multi-glyph cluster paint
A paint group is one extended grapheme cluster, not one shaper byte offset,
and every drawable member paints at the shaper's pen. The per-cell advance
gate skips multi-member groups (their advances are intra-cluster pen steps)
and measures the shaper's own cell count, so a wide ambiguous cluster stays
shaped under
wide. RealGridRenderercapture (Noto fonts, 10x22 cell),painted glyphs before -> after:
किक्षกำকে가🇫🇷/🇫🇮Deterministic
FakeShapertests pin the same invariants without host fonts(two-member one-cell cluster, two-offset conjunct, non-ligating flag pair,
ZWJ family ligature, wide ambiguous scalar), and the classic crossfont path
stays a documented degraded fallback (lead glyph plus zero-width marks).
Review rounds
distinguishable flags, full UAX fix(pty): silence Windows seam dead-code warnings without API changes #29 tables, GB9c, ambiguous-width span
math, cluster tests. Landed as [CTX-1609] feat(term): authoritative grapheme clusters and East Asian Width tables #2734.
restore_scrollback_textkeeps the base in the glyph slot, full GB4/GB5Control class, wide-ambiguous shaping, generator formatting, prepend
wording.
main; the drive-byshaped.rsdoc-linkfix is dropped in favour of [CTX-1611] ci: run the rustdoc gate in the quality job #2737 when that lands.
Verification
cargo fmt --all -- --checkcargo clippy -p bitty-term-state -p bitty-vt -p bitty-render -p bitty-runtime -p bitty-terminal --all-targets --locked -- -D warningscargo test -p bitty-term-state- all suites, including the 853GraphemeBreakTest-18.0.0.txtconformance samplescargo test -p bitty-vtcargo test -p bitty-render --lib- 384 passed, 1 failed:font_index::tests::boundary_truncated_index_is_rejectedis flaky onmain. Its fixed 5-byte truncation lattice interacts with thevariable-length temporary path in the serialized fixture, so repeated runs
of the same binary flip between pass and fail (observed on both this branch
and a clean
origin/mainworktree). This branch does not touchfont_index.rs; the test is owned by [render] Font index follow-ups: churn above caps, test gaps, PB-1 harness #2733 / [CTX-1610] fix(render): close the font index follow-ups #2736.cargo test -p bitty-terminal --bin bitty --locked -- --test-threads=1RUSTDOCFLAGS="-D warnings" cargo doc -p bitty-term-state -p bitty-vt -p bitty-render -p bitty-runtime -p bitty-terminal --no-deps --lockedCloses #1767