fix(desktop): render Nerd Font icons for any terminal font

Merged
KI
3mo ago
+292-39

Links

  • Issue: SUPER-1782 (Discord report: icons render as empty boxes with default settings, Menlo, and JetBrains Mono)

Summary

  • Quote every family name when building the terminal font stack — a digit-led name like 0xProto Nerd Font was invalid unquoted CSS and silently invalidated the whole stack (WebGL atlas fell back to 10px sans-serif: every icon tofu, cell metrics broken).
  • Keep private-use-area icons rendering for any chosen font by merging Nerd Font fallbacks into every stack: the well-known names (now including Symbols Nerd Font) plus the Nerd Fonts actually installed on the machine, detected via queryLocalFonts.

Why / Context

Chromium performs no system font fallback for PUA codepoints — an icon glyph must come from a font explicitly in the declared font-family list. Two bugs guaranteed tofu:

  1. Unquoted stack. The persisted setting is a bare family name and sanitizeTerminalFontFamily returned it unquoted. Families that aren't valid unquoted CSS idents (0xProto Nerd Font, 3270 Nerd Font) invalidate the entire value; canvas ctx.font keeps its previous value, so the WebGL glyph atlas rasterized in sans-serif (CSS.supports("font-family", "0xProto Nerd Font, monospace") → false).
  2. Dropped fallbacks. Picking any font in settings produced <font>, monospace, discarding the default stack's Nerd Font tail — so a non-Nerd primary (Menlo, JetBrains Mono, exactly what the reporter tried) could never render an icon even with a Nerd Font installed.

How It Works

  • sanitizeTerminalFontFamily is now one parse → validate → build pipeline. Every valid path goes through buildIconCapableStack: non-generic names quoted, icon fallbacks merged (deduped, inserted before the generic tail, never displacing the primary), and a generic monospace tail appended. The old raw pass-through returns are gone, and a latent case-sensitivity bug in serializeFontFamilyList is fixed.
  • New appearance/installed-nerd-fonts.ts enumerates installed Nerd Font families once per renderer lifetime via queryLocalFonts (the same API the settings font picker already uses): Propo/NFP variants excluded (proportional icons break cell metrics), Mono variants sorted first, capped at 8.
  • useTerminalAppearance feeds the detected families in via react-query; live terminals restyle through the existing updateAppearance path. The default (unset) stack gets the detected families too, so icons work out of the box with any installed Nerd Font, not just the hardcoded names.

CSS font matching is per-character, so fallbacks only ever supply glyphs the chosen font is missing — ASCII always renders in the user's chosen font.

Manual QA Checklist

Verified in the dev app over CDP (screenshots on the Linear issue thread workflow; all six icon planes exercised: powerline, devicons, seti, Font Awesome, octicons, supplementary-plane material):

  • Font set to 0xProto Nerd Font (invalid-unquoted name): previously double-spaced text + zero icons; now correct metrics and all icons render
  • Font set to Menlo (no nerd glyphs): icons render via detected installed Nerd Fonts, ASCII stays Menlo
  • Default settings (no font chosen): detected fonts merge into the default stack, icons render
  • Live terminals pick up a settings change without recreating the session (existing updateAppearance path)

Testing

  • bun run typecheck (desktop)
  • bun test src/renderer/lib/terminal/ — 340/340 (19 in the appearance suite, 8 new)
  • Biome clean on changed files

Known Limitations

  • A machine with zero Nerd Fonts installed still shows tofu — no stack can supply missing glyphs. The settings page already warns when a chosen font isn't installed.

Follow-ups

  • Consider bundling Symbols Nerd Font (~2 MB) as a @font-face fallback like Ghostty/WezTerm, so icons work with no Nerd Font installed at all. Left out here: the app currently bundles no fonts, so that's a size/licensing decision.

https://claude.ai/code/session_01RqqJQQY4jyCBJvsqekDURb


Summary by cubic

Fixes SUPER-1782: Nerd Font icons no longer render as empty boxes when the terminal font is anything but the default.

Previously, selecting a font like Menlo dropped the Nerd Font fallbacks, and names that aren't valid CSS (like digit-led 0xProto Nerd Font or ones ending in a backslash) invalidated the entire font stack, so the glyph atlas fell back to sans-serif. Now every family name is quoted and escaped, and every stack gets Nerd Font fallbacks — both the well-known names and Nerd Fonts installed on the machine, detected via queryLocalFonts. Icons render for any chosen font; ASCII text still renders in the user's font.

Known limitation

  • A machine with no Nerd Fonts installed still can't render icons; the stack can't supply missing glyphs.

Summary by CodeRabbit

  • Improvements

    • Terminal rendering now provides more reliable icon and glyph support by detecting installed Nerd Fonts.
    • Font fallback handling preserves monospace formatting and avoids duplicate or invalid font names.
    • Supports additional Nerd Font naming variants while excluding incompatible proportional fonts.
  • Bug Fixes

    • Improved terminal appearance when configured fonts are unavailable or contain special characters.
    • Added safer fallbacks when local font detection is unavailable or unsuccessful.