Extend Ghostty CJK font-fallback injection to symbol ranges (⬡ U+2B21, ▰/▱ gauges)
Summary
- Ghostty's
CTFontCollectionscoring indiscoverFallback()(src/font/discovery.zig) is monospace-biased: when a codepoint isn't in the configured font, it can pick whatever installed "monospace" font also claims coverage instead of the narrower substitute CoreText's ownCTFontCreateForStringcascade would choose. - cmux already works around this for CJK ranges via
loadCJKFontFallbackIfNeeded(#1017 /GhosttyConfigDiscovery.autoInjectedCJKFontMappings), but that injection is scoped to CJK-only ranges. Nanako0129/coralline#47traced this exact scoring bug through the Geometric Shapes (▰/▱/●/○) and Miscellaneous Symbols and Arrows (⬡U+2B21,⬢U+2B22) ranges, used by status-line tools rendering gauges/icons inside the terminal — and confirmed it reproduces specifically inside cmux (which vends its own Ghostty fork with the identicaldiscovery.zigfallback logic for the CoreText path).- This extends the same
font-codepoint-mapauto-injection mechanism to those symbol ranges, pointing them atApple Symbols(the font CoreText's own cascade resolves to for these ranges), so the fallback choice is predictable instead of landing on an arbitrary, potentially much wider "monospace" font. - Like the CJK path, injection only happens when the user hasn't already configured
font-codepoint-map, an explicit multi-fontfont-familyfallback chain, or a primary font that already covers the range — so it never overrides user-managed fallback.
Changes
GhosttyConfigDiscovery.swift: addssymbolRanges,symbolFallbackFont,symbolCoverageSampleCharactersByRange,symbolFontMappings(),autoInjectedSymbolFontMappings(),shouldInjectSymbolFontFallback().GhosttyTerminalView.swift: wiresloadSymbolFontFallbackIfNeededintoloadDefaultConfigFilesWithLegacyFallbackright after the existing CJK loader, plus thin static forwarders mirroring the CJK ones.GhosttyConfigDiscoveryTests.swift: newGhosttyConfigDiscoverySymbolTestssuite covering mapping generation and override precedence.
Test plan
-
swift test --filter GhosttyConfigDiscoveryinPackages/macOS/CmuxTerminalCore— 23/23 pass, including the 6 new symbol-fallback tests. - Full
cmuxapp-target build (xcodebuild -scheme cmux, via./scripts/reload.sh) — passes. The earlierzig 0.15.2gap was environment-specific and resolved with./scripts/setup.sh(zig 0.16.0, cachedGhosttyKit.xcframework). Build then hit an unrelated pre-existingmainbug (CLI/CMUXCLI+AgentHookFailureReporting.swifthad a non-exhaustive switch missingAgentHookFailureStage.journalAppend, from an unrelated upstream commit); fixed via a cherry-picked commit (fix: handle AgentHookFailureStage.journalAppend in failure reporting) so this branch builds clean end to end. - Manual repro: launched a tagged Debug build with an isolated
XDG_CONFIG_HOMEpointing atfont-family = JetBrainsMono Nerd Font(no CJK language, no explicitfont-familyfallback chain, nofont-codepoint-map). Printed⬡ ⬢ ▰ ▱ ● ○inside the terminal — all render as compact, near-1-cell-width, predictable glyphs, not an arbitrary wide substitute.
🤖 Generated with Claude Code
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by cubic
Extends Ghostty's font-fallback auto-injection to symbol codepoints (⬡ U+2B21, ▰/▱ gauges) so status-line glyphs resolve to Apple Symbols instead of an arbitrary wide monospace font. Injection matches CoreText's cascade and only covers codepoints the configured font — or the default embedded JetBrains Mono face, when no font-family is set — doesn't already render.
- Skips injection when the user has
font-codepoint-mapor a multi-entryfont-familychain, and fails closed when the configured font can't be probed (for both symbol and CJK injection). - Shares one config scan and one
font-codepoint-mapdirective builder between the CJK and symbol loaders so the two paths can't drift apart; coverage probing handles non-BMP codepoints via surrogate pairs. - Adds tests for per-codepoint filtering, default-face coverage (with a drift check against Ghostty's embedded JetBrains Mono that skips when the submodule isn't checked out), surrogate pairs, and fail-closed behavior.
Summary by CodeRabbit
-
New Features
- Added automatic symbol/pictographic font fallback by discovering uncovered symbol codepoint ranges and injecting matching
font-codepoint-mapdirectives when needed.
- Added automatic symbol/pictographic font fallback by discovering uncovered symbol codepoint ranges and injecting matching
-
Bug Fixes
- Improved fallback injection rules to avoid overriding user-provided
font-codepoint-mapor explicit multi-stepfont-familyfallback chains. - Tightened “fail-closed” behavior so fallback auto-injection is skipped when required fonts can’t be verified.
- Improved fallback injection rules to avoid overriding user-provided
-
Tests
- Added coverage for symbol mapping discovery, injection filtering using glyph coverage probing, consistency checks for injection decisions, and CJK fail-closed behavior.
[!NOTE]
Low Risk
Startup-only Ghostty config injection for font fallbacks; behavior is gated on user config and glyph coverage, with no auth or data-path changes.
Overview
Adds symbol-glyph font-codepoint-map auto-injection alongside the existing CJK workaround so glyphs like ⬡ (U+2B21) and ▰/▱ gauges map to Apple Symbols instead of an arbitrary wide monospace fallback from Ghostty’s CoreText scoring.
Injection is per codepoint (with coverage probing via new fontContainsGlyph, including surrogate pairs), skips user font-codepoint-map / multi-font-family chains, and when there is no font-family only overrides codepoints the embedded default JetBrains Mono lacks. CJK auto-injection now fails closed when the configured font family cannot be resolved, matching the symbol path.
GhosttyTerminalView resolves config scan paths once, runs the new symbol loader after CJK, and shares loadInjectedFontCodepointMap for both. Tests cover override rules, partial Nerd Font coverage, default-face filtering, and vendored-font drift for defaultFaceCoveredSymbolCodepoints.
Reviewed by Cursor Bugbot for commit 79da9c0a84390ea85254f26958e3f8ba578b7546. Bugbot is set up for automated code reviews on this repo. Configure here.