contour-terminal / contour

Modern C++ Terminal Emulator
http://contour-terminal.org/
Apache License 2.0
2.31k stars 100 forks source link

Assign unicode ranges to fonts #1374

Open classabbyamp opened 6 months ago

classabbyamp commented 6 months ago

Abstract

nerd-fonts are a common way to add special symbols in terminal UIs (shell prompts, editors, etc). There are two ways this is implemented, a patched font or a symbols-only font. I prefer to use the symbols-only font because it allows for more flexibility and I don't need to install 2GB worth of duplicate fonts, but it does mean some form of fallback mechanism is necessary. It seems that currently this does partially work:

image

(kitty left, contour right; notice the incorrect symbol for the >)

Motivation

To ensure that certain ranges of codepoints have the correct font, I propose a configuration option that allows for assigning ranges to certain fonts. I suspect this assignment might already be possible under-the-hood, given the font.emoji config option.

Specification

My thought is something like:

font:
  symbols:
    - range: U+E5FA-U+E62B
      family: "Symbols Nerd Font"
    - range: U+E700-U+E7C5,U+F000-U+F2E0
      family: "Symbols Nerd Font"

Other Implementations

https://sw.kovidgoyal.net/kitty/conf/#opt-kitty.symbol_map

christianparpart commented 6 months ago

Ranges for custom assignment of codepoints to glyphs is AFAIK only available on Kitty, right? Or do we have other TEs allowing that as well?

If I am not mistaken, on Linux at least, you could use fontconfig to achieve the same. Googling around, I found this: https://stackoverflow.com/questions/47501411/how-to-set-font-per-unicode-range-codepoint-in-fontconfig I'd have to try it myself, but I think that would be a proper way to do it. Plus point: it would work on every application automatically then.

On the other hand, we planned to integrate "Symbols Nerd Font" (and others) for convenience into Contour natively anyways (#170).

classabbyamp commented 6 months ago

Ranges for custom assignment of codepoints to glyphs is AFAIK only available on Kitty, right? Or do we have other TEs allowing that as well?

not sure, I've used kitty for a while and don't know the whole landscape.

If I am not mistaken, on Linux at least, you could use fontconfig to achieve the same.

I was going to say I already had a fontconfig conf for this but it seems it doesn't do that. Will try the fontconfig conf method.

0x5c commented 4 months ago

So using fontconfig for that seems simply impossible (for an user) to do.

There's two ways to promote a font; locale shenanigans (can't work; "dev icons" isn't a locale) or carefully designing your font priority list like a bonzai garden, which is impossible since there's already font priorities set by the system fontconfigs.

Even if this worked, it wouldn't work on other platforms.

On the other hand, we planned to integrate "Symbols Nerd Font" (and others) for convenience into Contour natively anyways (https://github.com/contour-terminal/contour/issues/170).

While I don't have a strong opinion on that, it is not a suitable answer to the problem; It's a forever incomplete solution that only covers one potential use-case. It's worth considering that supersizing the terminal for each special-use font that a user has requested will have undesirable effects, like causing the bundled fonts to not be skippable nor updateable without a terminal update. Some of these fonts can also break use-cases that aren't broken with a normal monospace font: for the entirety of Nerdfont's 2.x releases, it's Material Design Icons were located at incorrect codepoints, clobbering some asian scripts. Preloading box-drawing characters in terminals doesn't have that problem, since the character set is extremely small, and is located in a dedicated and standardised Unicode block.