How can I use terminfo entries on FreeBSD?

The conventional way to convert terminfo to termcap is with

infocmp -Cr

The infocmp option -C tells infocmp to use termcap names, and the -r option tells it to translate terminfo capabilities to termcap format. Some (such as the expressions used in sgr) will not translate, and infocmp may leave commented-out capabilities if there is enough space.

By "enough space", refers to the fact that real termcap applications allow only 1023 bytes in a description. FreeBSD uses ncurses underneath, but some applications make assumptions about the entry length.

FreeBSD however does have a termcap file which is independent of ncurses. There also is a "port" for ncurses, which some find useful.

By the way, you may be referring to this: termite/termite.terminfo. If you translated it, you might see something like

# vim: noet:ts=8:sw=8:sts=0
# (untranslatable capabilities removed to fit entry within 1023 bytes)
# (sgr removed to fit entry within 1023 bytes)
# (acsc removed to fit entry within 1023 bytes)
# (terminfo-only capabilities suppressed to fit entry within 1023 bytes)
xterm-termite|VTE-based terminal:\
        :am:hs:km:mi:ms:xn:\
        :co#80:it#8:li#24:\
        :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\
        :K2=\EOE:LE=\E[%dD:RI=\E[%dC:SF=\E[%dS:SR=\E[%dT:\
        :UP=\E[%dA:ae=\E(B:al=\E[L:as=\E(0:bl=^G:bt=\E[Z:cd=\E[J:\
        :ce=\E[K:cl=\E[H\E[2J:cm=\E[%i%d;%dH:cr=^M:\
        :cs=\E[%i%d;%dr:ct=\E[3g:dc=\E[P:dl=\E[M:do=^J:\
        :ds=\E]2;\007:ec=\E[%dX:ei=\E[4l:fs=^G:ho=\E[H:im=\E[4h:\
        :is=\E[!p\E[?3;4l\E[4l\E>:k1=\EOP:k2=\EOQ:k3=\EOR:\
        :k4=\EOS:k5=\E[15~:k6=\E[17~:k7=\E[18~:k8=\E[19~:\
        :k9=\E[20~:kD=\E[3~:kI=\E[2~:kN=\E[6~:kP=\E[5~:kb=\177:\
        :kd=\EOB:ke=\E[?1l\E>:kh=\EOH:kl=\EOD:kr=\EOC:\
        :ks=\E[?1h\E=:ku=\EOA:le=^H:md=\E[1m:me=\E[0m:mh=\E[2m:\
        :mm=\E[?1034h:mo=\E[?1034l:mr=\E[7m:nd=\E[C:rc=\E8:sc=\E7:\
        :se=\E[27m:sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:te=\E[?1049l:\
        :ti=\E[?1049h:ts=\E]2;:ue=\E[24m:up=\E[A:us=\E[4m:\
        :vb=\E[?5h\E[?5l:ve=\E[?12l\E[?25h:vi=\E[?25l:\
        :vs=\E[?12;25h:

There are a few errors in the terminfo entry (VTE does not support meta mode, for instance). Also, in termcap format you may notice that most of the function-keys go away (1023-byte limit).

Further reading:

  • infocmp - compare or print out terminfo descriptions
  • infotocap - convert a terminfo description into a termcap description
  • tctest – A Termcap Test Utility

Sometimes you need to do some manual changes to translate things properly.

I've made the following changes, to get it to translate the "important" parts of the desription.

  • Removed capabilities that cannot be represented in termcap format:
    • Dynamic color changing (ccc/initc)
    • Multi-attribute setting sequence (sgr)
    • Visual Bell (flash, requires intermediate delay which doesn't work in termcap)
  • Removed capabilities that aren't useful:
    • VT100 box drawing characters (smacs/rmacs/acsc, also changed sgr0)
    • 8-bit meta key (km/smm/rmm), also Thomas Dickey mentioned it doesn't actually work.
    • Printing (mc5i/mc0/mc4/mc5)
    • Blinking cursor (cvvis, also changed cnorm)
    • HP curses extensions (meml/memu)
    • Dynamic changing of tab stops (hts/tbc)
    • Infrequently used attributes (dim/invis)
  • Removed capabilities that are rarely used and excessively long
    • Shifted function/cursor keys (kf13+, kLFT/etc [upper-case names], kind, kri [used for shift-up/down])
    • Long-form init and reset sequences (is2/rs2)
    • Terminal identification and response (u8/u9)
  • Rewrote some things to fit better / be compatible with termcap
    • Changed setab/setaf to less efficient termcap-compatible version
    • Changed smkx/rmkx/clear to be shorter

This got it down to 1001 characters without sacrificing anything "important" (in particular, it still supports 256 colors and setting the title bar text)

xterm-termite|VTE-based terminal:\
    :NP:am:hs:mi:ms:ut:xn:\
    :Co#256:co#80:it#8:li#24:pa#32767:\
    :@7=\EOF:@8=\EOM:AB=\E[48;5;%dm:AF=\E[38;5;%dm:AL=\E[%dL:\
    :DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:F1=\E[23~:F2=\E[24~:\
    :IC=\E[%d@:K2=\EOE:Km=\E[M:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:\
    :SA=\E[?7h:SF=\E[%dS:SR=\E[%dT:UP=\E[%dA:ZH=\E[3m:\
    :ZR=\E[23m:al=\E[L:bl=^G:bt=\E[Z:cb=\E[1K:cd=\E[J:ce=\E[K:\
    :ch=\E[%i%dG:cl=\E[H\E[J:cm=\E[%i%d;%dH:cr=^M:\
    :cs=\E[%i%d;%dr:cv=\E[%i%dd:dc=\E[P:dl=\E[M:do=^J:\
    :ds=\E]2;\007:ec=\E[%dX:ei=\E[4l:fs=^G:ho=\E[H:im=\E[4h:\
    :k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:k5=\E[15~:k6=\E[17~:\
    :k7=\E[18~:k8=\E[19~:k9=\E[20~:k;=\E[21~:kB=\E[Z:kD=\E[3~:\
    :kI=\E[2~:kN=\E[6~:kP=\E[5~:kb=\177:kd=\EOB:ke=\E[?1l:\
    :kh=\EOH:kl=\EOD:kr=\EOC:ks=\E[?1h:ku=\EOA:le=^H:md=\E[1m:\
    :me=\E[m:mr=\E[7m:nd=\E[C:op=\E[39;49m:r1=\Ec:rc=\E8:\
    :sc=\E7:se=\E[27m:sf=^J:so=\E[7m:sr=\EM:ta=^I:te=\E[?1049l:\
    :ti=\E[?1049h:ts=\E]2;:u6=\E[%i%d;%dR:u7=\E[6n:ue=\E[24m:\
    :up=\E[A:us=\E[4m:ve=\E[?25h:vi=\E[?25l:

Note that all indented lines should use tabs for indentation.

The important thing for color support is the AB and AF capabilities - they couldn't be translated automatically from setab/setaf because it's a 256-color terminal. The relevant part of the termcap is :AB=\E[48;5;%dm:AF=\E[38;5;%dm:; for non-256-color mode it would be :AB=\E[4%dm:AF=\E[3%dm: (and Co#8, pa#64 to match).