The Joy of Alacritty

I have been using iTerm2 for ages and would have continued had a recent update not broken ligatures for me. I am so glad it did, because it lead me to Alacritty.

What

Alacritty does all the things I need and may even be faster than iTerm2. It is also a kick-butt Rust based project. What more could you ask for? If you say tabs, well then no, Alacritty does not support tabs. I use Tmux in place of tabs, so for me this just means that Alacritty is a better targeted solution.

I need a terminal emulator to be fast, support color, ligatures, Tmux, and VIM simultaneously and seamlessly. Alacritty does all this very well.

If I notice terminal introduced latency then it is too slow, if I do not, then it is fast enough. I use color to provide semantic clues. I expect at least 256 colors. Tmux and VIM should work together largely the way they work separately. Ligatures require more explanation.

A ligature is a single character representation of a symbolic concept resulting from the joining of two or more characters1. It is useful in some programming languages to simplify the display of compound ASCII symbols.

Here are two ways to represent not equal.

Not Equal - ASCII
Not Equal - Ligature

I use ligatures as a way to display symbols, comprised of multiple ASCII characters, as a simpler rendering, without altering the actual source characters. Here is an example from Fira Code that shows and example of the ASCII saved in a file, on the right, and the ligature representation displayed, on the left.

comparing original and ligature versions of Fira Font

This enables me to view some characters as ligatures, but not to enforce my preference on other users of a source file. I like having the control of when to obscure the actual ASCII with ligatures. When I am editing a line, I like to see the original ASCII on that line so I can see what I am editing. The iTerm2 update forced the display of ligatures all the time. The iTerm2 configuration for this feature was disabled.

Always display ligatures

In order for me to control the expression of ligatures, I need the terminal emulator to display the actual character. I use tools like enomsg/vim-haskellConcealPlus to obscure the ASCII with ligatures when that is my preference.

Notice how some of the characters are displayed as ligatures even on the cursor line. The cursor is narrow in the in the screen-shot but look at the character just left of liftIO.

How

Here is how I got Alacritty working on my Mac (Sierra 10.12.x). If you do not use Mac then your setup will be different.

Fonts

I am using two fonts, Fira Code and Menlo. I beleive that Menlo ships with Mac, but Fira Code does not. Open Font Book to ensure both are installed. To install Fira Code, simply follow the instructions here. I just downloaded the Fira Code fonts and installed them with Font Book, rather than using homebrew. Once installed you should see the following in Font Book.

Fira Code
Menlo

Tmux

Make sure Tmux is installed and reasonably updated. I found that the version from homebrew did not work fully, so I uninstalled it and installed the following from macports2.

  • tmux @2.5_0
  • tmux-pasteboard @2.6_0

I updated my ~/.tmux.conf to change the default terminal identifier.

set -g default-terminal "tmux-256color"

Alacritty

Manually install Alacritty as shown here, i.e. do not use homebrew.

Edit the .config/alacritty/alacritty.yml configuration file.

Update the fonts

I am using Fira Code for regular and bold fonts. I am using Menlo for Italic.

# Font configuration (changes require restart)
font:
  # The normal (roman) font face to use.
  normal:
    family: Fira Code
    # Style can be specified to pick a specific face.
    style: Regular

  # The bold font face
  bold:
    family: Fira Code
    # Style can be specified to pick a specific face.
    style: Bold

  # The italic font face
  italic:
    family: Menlo
    # Style can be specified to pick a specific face.
    style: Italic

Misc

The terminal setting should look like.

  TERM: xterm-256color

Look over the rest of the config and ensure it matches your environment. I also changed the bash used to the version installed in /opt/local/bin.

shell:
   program: /opt/local/bin/bash
   args:
      - --login

The colors can be manually modified by providing the hex value.


  # Normal colors
  normal:
    black:   '0x000000'
    red:     '0xd54e53'
    green:   '0xb9ca4a'
    yellow:  '0xe6c547'
    blue:    '0x7aa6da'
    magenta: '0xc397d8'
    cyan:    '0x70c0ba'
    white:   '0xffffff'

If you are moving from another terminal emulator, like iTerm2 you can view the defined colors, for example from iTerm2ColorSchemes.com, and grab the hex value with Digital Color Meter.

Open Digital Color Meter and then menu, view, display values, and select as hexadecimal. Then fly over the color and then hit Shift - Command - c, to copy the hex value to the clipboard. Then from the clipboard, you can paste them to the .config/alacritty/alacritty.yml configuration file for the given color.

Also if you like the color schemes at iTerm2ColorSchemes.com you can find the scheme you like and read the termite config in github.

If for example you like the SoftServer scheme, you can view the hex values in github.com/mbadolato/iTerm2-Color-Schemes/blob/master/termite/SoftServer. The termite config file looks like this.

[colors]
background = #242626
cursor = #d2e0de
foreground = #99a3a2
color0 = #000000
color1 = #a2686a
color2 = #9aa56a
color3 = #a3906a
color4 = #6b8fa3
color5 = #6a71a3
color6 = #6ba58f
color7 = #99a3a2
color8 = #666c6c
color9 = #dd5c60
color10 = #bfdf55
color11 = #deb360
color12 = #62b1df
color13 = #606edf
color14 = #64e39c
color15 = #d2e0de
colorBD = #d2e0de
colorIT =
colorUL =

If manually editing is not your thing, there might be a color scheme that you can use. Nord Alacritty looks nice.

Man

I went ahead and added some color for Man pages also.

  • Update ~.bashrc
# color for less and man 
export MANPAGER='less -s -M +Gg'
export LESS="--RAW-CONTROL-CHARS"
lesscolors=$HOME/bin/.LESS_TERMCAP
[[ -f $lesscolors ]] && . $lesscolors
  • Create or edit ~/bin/.LESS_TERMCAP
export LESS_TERMCAP_mb=$(tput bold; tput setaf 2) # green
export LESS_TERMCAP_md=$(tput bold; tput setaf 6) # cyan
export LESS_TERMCAP_me=$(tput sgr0)
export LESS_TERMCAP_so=$(tput bold; tput setaf 3; tput setab 4) # yellow on blue
export LESS_TERMCAP_se=$(tput rmso; tput sgr0)
export LESS_TERMCAP_us=$(tput smul; tput bold; tput setaf 7) # white
export LESS_TERMCAP_ue=$(tput rmul; tput sgr0)
export LESS_TERMCAP_mr=$(tput rev)
export LESS_TERMCAP_mh=$(tput dim)
export LESS_TERMCAP_ZN=$(tput ssubm)
export LESS_TERMCAP_ZV=$(tput rsubm)
export LESS_TERMCAP_ZO=$(tput ssupm)
export LESS_TERMCAP_ZW=$(tput rsupm)
export GROFF_NO_SGR=1         

Enjoy

Here is are a few examples of the results.

This shows the way I use ligatures. Also note the italic comments.

Correct use of ligatures

Here is a Man page using color.

Ag Man Page


  1. This is a simplified definition. See a better one here.↩︎

  2. If I recall correctly the macports version has a patch of some kind.↩︎

Mark Mynsted
October 24, 2017