#14693

cli/list-fonts: add an interactive font picker to +list-fonts

Opendavidsanchez222wants to merge intofrom

conversion of https://github.com/ghostty-org/ghostty/discussions/14609 to a PR

the current ghostty +list-fonts just printing out the fonts to stdout could use an enhancement. it would be nice to have a way to see each font in a picker instead of having to toggle each one in the config file, reload the config and then repeat.

i (with the help of Claude Sonnet 5.5) implemented a TUI picker for list-fonts that is mostly the same as list_themes.zig. I reviewed it, tested it on macOS, and can explain how it works.

Demo:

https://github.com/user-attachments/assets/b2ee5af4-5e10-42cd-8d6e-e7eb54fce922

there was 2 approaches for this since each cell can only be rendered in the configured font:

  1. braille preview of each font. i did this in a separate tui side project with good results. however, i don't think its good enough because the user might be interested in slight intricacies in a font that braille might be too low-res to show
  2. load the font, rasterize the sample text with Ghostty's own font code, and send it as one image over the Kitty graphics protocol. This is what the branch does.

the existinglist_fonts.zig decides whether to launch the picker

list_fonts_picker.zig checks that the terminal supports Kitty graphics and reports its size in pixels. Otherwise you still get the searchable list, with a text note in place of the preview.

  • it pulls from the users configured theme so its not just a white/black screen picker like list-themes is.

  • pressing c will copy the line needed to add to the config. so in the demo above the user would receive font-family = "MesloLGL Nerd Font Mono" in their clipboard.

  • i did some rudemtary performance analysis and saw a 20MB increase in memory usage. about 25 ms per font selection change, and about 50 MB peak memory compared to 33 MB for the plain listing.

  • only tested on macOS so far

i think it would also be useful to add some icons/ligatures to the preview text in another commit. ligatures would need the shaper, so i'd look into that separately

AI disclosure

I used Claude Code (Sonnet 5.5) to help write this change. I reviewed, built and tested the change myself.

Activity

2
jcollierequested changes12d ago
jcollie12d ago

1: The picker should also show the bold, italic, and bold italic versions of thee font (if they exist). 2: This is going to be very bandwidth intensive. I'd suggest only sending a new image once the highlight settles on a new family so that doing a fast scroll through the families doesn't overwhelm. I'd also cache recently shown families so that the images don't need to be regenerated.