7

On my local Linux machine, I'm using termite (VTE-based). It comes with its own terminfo file (xterm-termite), which is not distributed with ncurses by default.

I try to connect to a remote FreeBSD server. Unfortunately, FreeBSD by default only uses the older termcap format. I haven't been able to find a way to convert terminfo to termcap. So, while I can compile a version of ncurses which includes terminfo support from the ports (devel/ncurses), ncurses applications will link to the system-supplied lib by default. This results in apps failing to launch:

$ echo $TERM
xterm-termite
$ toe | grep termite
xterm-termite   VTE-based terminal
$ tmux
open terminal failed: can't find terminfo database
$ htop
Error opening terminal: xterm-termite.

(toe lists terminfo entries)

How can I make FreeBSD use terminfo by default, or force applications to use the port-supplied ncurses lib, or at least convert terminfo to termcap data?

(I'm aware of the workarounds like setting TERM to a safe value like xterm-256color, but I think that defeats the purpose of terminfo)

  • 1
    Try infocmp -C to produce a termcap entry. – Mark Plotnick Jun 22 '16 at 16:37
  • @MarkPlotnick Thanks a lot, that works! I ran infocmp -C xterm-termite >> /usr/share/misc/termcap; cap_mkdb /usr/share/misc/termcap. Feel free to add it as an answer, so I can approve it. – Wilhelm Schuster Jun 22 '16 at 19:16
7

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:

  • Thanks a lot for the detailed explanation! I wonder why they haven't moved on to terminfo... That size limit for example seems arcane. – Wilhelm Schuster Jun 22 '16 at 20:47
  • Inertia, mostly. – Thomas Dickey Jun 22 '16 at 20:48
  • As noted above, some stuff is gets thrown away due to the size-limit. Colors are missing, unfortunately, but at least Backspace works now. – Wilhelm Schuster Jun 22 '16 at 20:58
  • The -T option of infocmp may work for you, but some applications may break. – Thomas Dickey Jun 22 '16 at 21:01
4

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).

  • Thank you for the answer and going out of your way of explaining how you got to the solution. I would say that @thomas-dickey 's answer still fits my question, which was more broader a not necessarily only for VTE-based terminals, better. I hope you can understand. – Wilhelm Schuster Sep 25 '16 at 18:47
  • @WilhelmSchuster My answer was intended to be reasonably general in explaining techniques for reducing a terminfo entry into something that can translate without omissions. Anyway, the important thing for color, as the issue you complained of was a lack of color, is :AB=\E[48;5;%dm:AF=\E[38;5;%dm: (or :AB=\E[4%dm:AF=\E[3%dm: for non-256color terminals) in the termcap, which is the same across most terminals and could have been added manually assuming there was enough room for it. But I'm not worried about who gets the accepted flag in any case, just glad I could help with your problem. – Random832 Sep 26 '16 at 2:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.