Yet another tech blog

Unknown Terminals and Remote Hosts

· Read in about 3 min · (607 Words)
linux termite ssh terminfo

For quite some time now I’ve been using i3 as my (tiling) window manager of choice. When I just started using it, I’ve coupled it with rxvt-unicode (aka urxvt) only because I noticed many other users of i3 were using it. In a certain point of time after using urxvt, I started to look for an alternative terminal that will be easier to configure and will support copy & paste to and from the clipboard out-of-the-box.

That’s when I found termite:

A keyboard-centric VTE-based terminal, aimed at use within a window manager with tiling and/or tabbing support.

termite delivered all the features I wanted while still remaining lightweight and snappy for use with i3. When I first tried to use termite, suddenly some keys where not performing the tasks they should.
For example: Backspace didn’t delete characters anymore, the Home and End buttons just inserted some weird characters into the shell, and even autocomplete didn’t work well. I remembered that I’ve encountered this kind of behavior in the past, and that it is somehow related to the TERM environment variable.

After some reading I realised that the TERM variable should be set to xterm-terminfo. So I did just that:

# ~/.zshrc
export TERM=xterm-color

And what do you know, everything worked just fine.

Wait.. What is This terminfo Anyway?

From TLDP:

Terminfo (formerly Termcap) is a database of terminal capabilities and more. For every (well almost) model of terminal it tells application programs what the terminal is capable of doing. It tells what escape sequences (or control characters) to send to the terminal in order to do things such as move the cursor to a new location, erase part of the screen, scroll the screen, change modes, change appearance (colors, brightness, blinking, underlining, reverse video etc.).

Also good to know that:

The terminfo database is compiled and thus has a source part and a compiled part.

So basically, terminfo supplies the application with the means to interact with different terminals in a device-independent manner.

Happy Ending!

Not just yet…
When I tried to work on remote hosts (via SSH) all the previous problems came back. But now, knowing what caused them, I quickly changed my shell configuration to set the TERM variable, restarted the shell, and…
I got some errors along the lines of unknown terminal type xterm-termite and open terminal failed: missing or unsuitable terminal: xterm-termite.

Let’s Fix That

It turns out that terminfo doesn’t contain the needed information in it’s database about how termite works.
One way of making things right will be to install termite on the remote host, and this should place the relevant terminfo files on the server. But this is not always possible as we might not have the privileges of the mighty root at our disposal in order to install packages on the host. And even if possible might not be the best solution.

The other approach is to manually insert the termite terminal capabilities to the terminfo database. We should first get the capabilities source file for termite. This could be done in more that one way. We can grab the termite.terminfo file from the project’s Github repo or extract it from a machine that has termite installed. To achieve the latter:

# On local host 
infocmp > termite.terminfo
# Then transfer the created file to the remote host (scp)

# On remote host
tic -x termite.terminfo

tic is the Terminfo Compiler, it takes source files that defines terminal capabilities and compiles them for terminfo to work with.
This will install the necessary file (locally to the user) for terminfo to support termite.
And we are done!

Happy New Year!

Comments