The hunt for a true color terminal

filed under terminal and linux

For a long time I've battled with getting a decent colour scheme in Vim and my terminal. The problem is that Vim is bounded by the colours provided by the shell - a 16 colour palette, or maybe even 256. 256 sounds all well and good but you essentially need to complete rewrite any Vim color scheme you find online as well as mangling your terminal's configuration, which is too time consuming to be worth the effort.

As it turns out, the simplest way to fix this problem is to use terminals and tools that support true color, so things will "just work". This, for me, involved doing the following:

  • start using neovim, which provides true color support when started with NVIM_TUI_ENABLE_TRUE_COLOR=1.
  • start using a patched tmux (true color patch).
  • start using a terminal supporting true color.

The first two checkpoints were simple enough, in so far as someone else had done all the work for me so I didn't have to do much more than install software. The final checkpoint was a source of frustration for me though.

I've been a long time user of urxvt, a terminal that provides pretty sane defaults in terms of handling backspace and delete keys and such (boo xterm). The urxvt developers don't care about true color support, and I'm certainly not interested in implementing it for them, so I had to start hunting for other terminals.

I don't particularly use features of terminals exhaustively (what they may even be), and I only really care that they don't have any UI elements dirtying up the screen, so I eventually settled on tinyterm, which I forked and improved (in my humble opinion).

When I started using tinyterm, I found that it didn't actually support true color on my system. This was a result of it compiling against the vte package, which ships as 0.28.2 on Arch. True color support wasn't introduced until vte 0.35.1, so I needed to build against a newer version. I've opted to build against the absolute newest version, 0.40.2, which ships as vte3 on Arch.

There are only two things I used in urxvt that I cared about. One of them was the urxvt-font-size plugin for dynamically increasing the font size of a given terminal. This was trivial enough to implement directly in tinyterm, and as a bonus provides a finer granularity for resizing than urxvt did.

The second thing is the part that took the most work, implementing multiple terminals as a single application instance. urxvt provides two commands, urxvtd and urxvtc, which let you start up multiple terminal windows under one running process, to save memory. This has the downside that if it crashes it will take out all of your terminals, but in five years I've never seen that happen. I've implemented the same thing in tinyterm by using Gtk's GtkApplication. There are a few little issues I need to sort out with it at the moment (e.g. tinyterm -h or tinyterm -v will kill all of your windows, but aside from those small issues it works very well.

urxvt's implementation meant that when you started up your X server you needed to run up urxvtd & as part of your .Xinitrc. This had the downside that if you restarted your X server, you'd end up with multiple urxvtd instances running, which is ugly. Because of how GtkApplication works, I don't need to do this for tinyterm. This means that the master process is spun up on demand, which I think is pretty neat.

So that's about it really. It was a small adventure to get going, but it was worth it I think.

Why not just use GVim? It has true color support!

I don't want to. I like running Vim in a terminal. That's all.

Related Posts