alacritmux: Tmux Pane Font Resize

Dan Aloni
3 min readApr 26, 2019

--

A patched Alacritty attached to a patched Tmux, with panes fonts of different sizes

Character-based computer terminals go back more than 50 years, from when big computer manufacturers have connected their time-sharing black-on-white or green-lit terminals to heavy computers that resided in other rooms in the building. The American National Standards Institute established as the body that took upon itself to define the standard codes in which terminals send and receive codes to their corresponding computer.

It is mildly curious, that in 2019, under the age of heavy web-oriented many developers still use text-based computer terminals. Vim, an editor originally used in the terminal, is ranked 25.4% in the Stack Overflow’s 2019 developer survey.

The Problem

Terminals still have uniformly-sized text. This applies also to the completely virtual ones that are managed by Tmux and all the very popular terminal emulator programs that are widely used by developers.

Do you see uniformly sized text when browsing the web? Likely not, and it’s a a large contrast. Why do computer terminals have uniform character grids? Mainly, because they always did. Terminals are quite limited. Extending them requires extending standards.

The Setup

I took the sources of two popular programs —

  • Tmux — A terminal multiplexer for Unix-like operating system.
  • Alacritty — A cross-platform, GPU-accelerated terminal emulator.

Some hours and 1,000 lines of code later, I have implemented pane font resize, as illustrated in the screen shot above. I’ve made the code available in the alacritmux Github repository.

Alternatives

Q: Why not launch two Alacritty instances and connect to two different Tmux session?

Q: Why not use a terminal emulator that supports tabs, then open two ssh sessions to connect to different Tmux sessions in the same remote Tmux instance?

A: Because these workarounds suck — I think that the workflow of using a single Tmux session should not vary, simply because I want a different font size for my different Tmux panes.

Implementation

I’d wager that the developers of both Tmux and Alacritty will most raise eyebrows at what I did, so I’ll try to make the story short:

  • Alacritty sends an ANSI code that tells Tmux about the font sizes that it supports.
  • Alacritty sends a special ANSI code that Tmux understands as “Change the font size of that pane you’re currently at”. Currently only enlarging the font is supported, therefore allowing for less text.
  • Tmux calculates what should be the grid size for the enlarged text, based on the regular grid size metrics. It therefore shrinks the terminal of the corresponding pane to that smaller size. It sends this information to Alacritty in the form of a ‘Grid Zoom Vector’.
  • Alacritty receives this ‘Grid Zoom Vector’, which tells it the following: for the specific portions of the grid, the text should be enlarged using a certain font size, with a certain reduction in displayed text.
  • Alacritty takes the top-left cut of each of the zoom regions and uses it as the text to render in that zoom region.
  • For any change of zoom regions configuration, Tmux updates Alacritty.
  • For any change of the supported font sizes, Alacritty updates Tmux.

Going Forward

First, I am far from being under any delusion that these changes find themselves into official versions of the relevant programs any time soon.

For us to see this feature in our favorite terminal emulators and terminal multiplexer(s), let us consider the following:

  • Agreement regarding the terminal protocol extension. This extension is not trivial and there probably many corner cases worth considering. Hello ANSI?
  • Agreement regarding actual implementation with the authors of Tmux and Alacritty, and possibly other terminal emulator programs. There are a lot more terminal emulator programs than multiplexers, because implementing a multiplexer is a much harder than implementing a terminal emulator.
  • Stability of implementation all around.

If you deem this feature important, please feel free to assist.

--

--

Dan Aloni

Coder. C, Rust, Haskell, Python and more. Tinkering with Linux🐧 kernels for fun and profit.