Sunday, May 10, 2026

Alacritty with Terminus On MacOS

Getting Alacritty to render Terminus font nicely along with having those nice nerd font symbols on MacOS  turned out to be much more of a hassle then I ever expected it to be.  With iTerm2, it was simply a matter of installing the Terminess Nerd Font and disable anti-aliasing, but with Alacritty there's a lot more steps involved.

Installing Terminus


Installing Terminus on MacOS can be done through Brew for both Terminus TTF and Terminess (the Nerd Font equivalent).  Make sure to do the following:
  1. Go to Font Book and check that the fonts are all activated.
  2. Make sure you have the right family name and style as Alacritty is case sensitive and both needs to be entered into the config exactly or Alacritty will give you a misleading error message.

Disabling Anti-Aliasing


Terminus is a font that might look worse with anti-aliasing.  Both the Terminus TTF and Terminess did not look as clear and as sharp compared to what I'm used to.  iTerm has a checkbox to turn it off but Alacritty requires you to do this from the OS:
defaults write org.alacritty AppleFontSmoothing -int 0
To turn it back on:  
defaults delete org.alacritty AppleFontSmoothing

Installing a Better Terminus


Alacritty couldn't render either of the above fonts very clearly.  On programmingfonts.org, I found another Terminus font that looked nice on the browser called Consoleet Terminus



I installed it on to MacOS but getting Alacritty to recognize it had me pulling out my hair.

[font]
size = 18.0
normal = { family = "Consoleet Terminus-18", style = "medium" }
bold = { family = "Consoleet Terminus-18", style = "bold" }
Notice what's unusual about the configuration that finally worked in Alacritty?  Some Terminus fonts don't have "Regular" styles and only define it as "Medium".  In the case of Consoleet Terminus, the styles are all lowercase.  If it is capitalized (e.g. "Medium" instead of "medium") then there will be an error.

I finally got the same nice looking terminal except it doesn't have those Nerd Font symbols.

 Installing Nerd Font Symbols


On Linux, it is easy to tell it that if a font doesn't have a symbol to go to a fallback font that does have it and use that one.  MacOS doesn't allow that so I had to merge a font that has it into Consoleet Terminus.  The problem is that most fonts with the symbols are scalable while classic version of Terminus fonts (like Consoleet) are not.   That's why you'll see individual font files for specific sizes.  In my case, the Consoleet em size is 36 units (ascent 30, descent 6) while Terminess will be 2048 — so the symbols are coming in roughly 56× too large.

The following script got me the right numbers to use to figure out what size I need to extract:
#!/usr/local/bin/bash
SYMBOL_REGULAR="$HOME/Library/Fonts/TerminessNerdFont-Regular.ttf"
SYMBOL_BOLD="$HOME/Library/Fonts/TerminessNerdFont-Bold.ttf"
mkdir -p ~/merged-fonts

declare -A SYMBOL_MAP=(
  [/Library/Fonts/consoleet_ter18nr.otf]="$SYMBOL_REGULAR|medium"
  [/Library/Fonts/consoleet_ter18br.otf]="$SYMBOL_BOLD|bold"
)

for f in "${!SYMBOL_MAP[@]}"; do
  IFS='|' read -r symbol style <<< "${SYMBOL_MAP[$f]}"
  name=$(basename "$f" .otf)
  family="Consoleet Terminus-18 Nerd"
  psname="ConsoleetTerminus18Nerd-${style}"
  fullname="${family} ${style}"

  cat > /tmp/merge.pe <<EOF
Open("$f")
Print("Destination em: " + \$em)
Print("Destination ascent: " + \$ascent + " descent: " + \$descent)
\$dst_em = \$em
\$dst_ascent = \$ascent
\$dst_descent = \$descent

Open("$symbol")
Print("Source em (before): " + \$em)
ScaleToEm(\$dst_ascent, \$dst_descent)
Print("Source em (after): " + \$em)
Generate("/tmp/scaled_symbol.ttf")
Close()

MergeFonts("/tmp/scaled_symbol.ttf")
SetFontNames("$psname", "$family", "$fullname", "$style")
Generate("$HOME/merged-fonts/${name}-merged.otf")
EOF
  fontforge -script /tmp/merge.pe
Then with the results, update the script to create the merged fonts:
#!/usr/local/bin/bash
SYMBOL_REGULAR="$HOME/Library/Fonts/TerminessNerdFont-Regular.ttf"
SYMBOL_BOLD="$HOME/Library/Fonts/TerminessNerdFont-Bold.ttf"
mkdir -p ~/merged-fonts

declare -A SYMBOL_MAP=(
  [/Library/Fonts/consoleet_ter18nr.otf]="$SYMBOL_REGULAR|medium"
  [/Library/Fonts/consoleet_ter18br.otf]="$SYMBOL_BOLD|bold"
)

for f in "${!SYMBOL_MAP[@]}"; do
  IFS='|' read -r symbol style <<< "${SYMBOL_MAP[$f]}"
  name=$(basename "$f" .otf)
  family="Consoleet Terminus-18 Nerd"
  psname="ConsoleetTerminus18Nerd-${style}"
  fullname="${family} ${style}"

  cat > /tmp/merge.pe <<EOF
Open("$f")
dst_ascent = \$ascent
dst_descent = \$descent
Print("Destination em: " + \$em + " ascent: " + dst_ascent + " descent: " + dst_descent)

Open("$symbol")
Print("Source em (before): " + \$em)
ScaleToEm(dst_ascent, dst_descent)
Print("Source em (after): " + \$em)
Generate("/tmp/scaled_symbol.ttf")
Close()

Open("$f")
MergeFonts("/tmp/scaled_symbol.ttf")
SetFontNames("$psname", "$family", "$fullname", "$style")
Generate("$HOME/merged-fonts/${name}-merged.otf")
EOF
  fontforge -script /tmp/merge.pe
Done

Once the script is run, validate it first:
fc-scan --format "%{family}\n%{fullname}\n%{postscriptname}\n%{style}\n" ~/merged-fonts/consoleet_ter18nr-merged.otf
fc-scan --format "%{family}\n%{fullname}\n%{postscriptname}\n%{style}\n" ~/merged-fonts/consoleet_ter18br-merged.otf
If there are no errors then install and validate:
cp ~/merged-fonts/consoleet_ter18*-merged.otf ~/Library/Fonts/
fc-match "Consoleet Terminus\-18 Nerd"
fc-match "Consoleet Terminus\-18 Nerd:style=bold"
Your final alacritty.conf file will be:
[font]
size = 18.0
normal = { family = "Consoleet Terminus-18 Nerd", style = "medium" }
bold = { family = "Consoleet Terminus-18 Nerd", style = "bold" }
Restart Alacritty.

 

No comments:

Post a Comment