Skip to content

Add RTL shaping support for cmux - #88

Draft
essamgouda97 wants to merge 11 commits into
manaflow-ai:mainfrom
essamgouda97:cmux-arabic-rtl-support
Draft

Add RTL shaping support for cmux#88
essamgouda97 wants to merge 11 commits into
manaflow-ai:mainfrom
essamgouda97:cmux-arabic-rtl-support

Conversation

@essamgouda97

@essamgouda97 essamgouda97 commented Jun 28, 2026

Copy link
Copy Markdown

Summary

  • bring the upstream Ghostty RTL shaping series into the cmux Ghostty fork
  • add the small compatibility adjustment needed for the cmux-pinned stream API
  • cover Arabic, Hebrew, Bengali, and mixed LTR/RTL shaping paths

Validation

  • zig build test -Dapp-runtime=none -Demit-macos-app=false -Demit-xcframework=false -Dtest-filter=arabic
  • zig build test -Dapp-runtime=none -Demit-macos-app=false -Demit-xcframework=false -Dtest-filter=hebrew
  • zig build test -Dapp-runtime=none -Demit-macos-app=false -Demit-xcframework=false -Dtest-filter=bidi
  • zig build test -Dapp-runtime=none -Demit-macos-app=false -Demit-xcframework=false -Dtest-filter=RTL
  • zig build test -Dapp-runtime=none -Demit-macos-app=false -Demit-xcframework=false -Dtest-filter=mixed
  • zig build test -Dapp-runtime=none -Demit-macos-app=false -Dtest-filter=Bengali
  • rebuilt GhosttyKit ReleaseFast xcframework for pinned cmux SHA 7a51798436fa2cfcfcc9a2ed1e109ba69bdb68f9 and validated the archive

Notes

This is based on the active upstream Ghostty RTL work in ghostty-org/ghostty#11079, applied to the cmux Ghostty fork so cmux can get native terminal shaping instead of adding text reordering in cmux itself.

The exact pinned branch used by the local cmux submodule is also published as essamgouda97/ghostty:cmux-arabic-rtl-support-pinned-cmux.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Adds native RTL shaping to cmux using itijah-based BiDi layout, bringing correct Arabic, Hebrew, and Bengali rendering in RTL and mixed-direction lines. Fixes combining-mark anchoring and overlap issues in both CoreText and HarfBuzz shapers.

  • New Features

    • Use itijah to compute visual runs and split rows at RTL/LTR boundaries.
    • Enable RTL shaping in CoreText and HarfBuzz; sort shaped cells by x for rendering.
    • Anchor clusters per cell so Arabic tashkeel and Bengali vowels attach to the correct base.
    • Support mixed-direction lines while preserving cursor/selection run splits.
  • Dependencies

    • Add itijah v0.2.1 (lazy) and integrate with shapers; reuse VisualLayoutScratch across runs.
    • Extend uucode tables with bidi_class, bidi_paired_bracket, joining_type, and is_bidi_mirrored.

Written for commit a7cfbb4. Summary will update on new commits.

Review in cubic

DiaaEddin and others added 11 commits June 28, 2026 02:31
CoreText emits glyphs in non-monotonic order for RTL runs containing
combining marks (tashkeel). The shaper was anchoring cell offsets to
run_offset.x (cumulative advances) instead of position.x (CoreText's
absolute glyph position), causing adjacent base characters to visually
overlap when tashkeel like shadda+kasra appeared at word endings.

Use position.x for RTL anchor writes in both the reset and mark-fallback
paths. Add a re-anchor path for the case where CoreText emits a
combining mark before its base glyph within the same cluster, which
caused overlap in multi-word phrases like "الحيِّ الذي".

Extract isArabicCombiningMark into a shared bidi_helpers module used by
both shapers. Add tashkeel overlap regression tests to both CoreText and
HarfBuzz shapers.

Also clean up the run iterator: cache row layout resolution across
calls, extract fontStyleForStyle/presentationForCell helpers, and
replace an unreachable with continue for neutral characters not found
in the current run font.
Bump itijah dependency to v0.1.8 and add .lazy = true to match
project convention. Extract duplicated font-resolution logic into
resolveFontInfo helper.
The existing tashkeel tests checked cluster assignments but not the
actual x_offset values that were broken. Add assertions that base
glyphs outside the tashkeel cluster have x_offset == 0, which catches
the position.x/run_offset.x divergence the previous commit fixed.
- Bump itijah to v0.2.1 (LTR fast path, hasStrongRtl, N0 IRS fix).
- Rewrite bidi_helpers comment to drop "emission behavior" jargon
  and explain the Arabic mark fallback in plain terms.
- Expand RTL path comments in coretext/harfbuzz and simplify the
  cluster_anchor_x init to a single appendNTimes call.
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 00f0b379-011a-4de9-af53-e8d5bce84bfa

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants