• Please review our updated Terms and Rules here

C code for terminal output using terminfo

RCourtney

Experienced Member
Joined
Dec 11, 2025
Messages
64
Looking for C libraries to write screen info using the terminfo system for compatibility.

Decades ago my employer only used specific terminals so we just used the escape sequences.
 
Lib termcap was used to to abstract screen positioning from terminal types. Download the GNU termcap code and compile.


README:
This is the GNU termcap library -- a library of C functions that
enable programs to send control strings to terminals in a way
independent of the terminal type. The GNU termcap library does not
place an arbitrary limit on the size of termcap entries, unlike most
other termcap libraries.

Most of this package is also distributed with GNU Emacs, but it is
available in this separate distribution to make it easier to install
as -ltermcap. However, use of termcap is discouraged. Termcap is
being phased out in favor of the terminfo-based ncurses library, which
contains an emulation of the termcap library routines in addition to
an excellent curses implementation. ncurses is available from the
usual GNU archive sites.

See the file INSTALL for compilation and installation instructions.
Additionally:

This package contains termcap.src, the latest official termcap data
file. By default, it is not installed. The current version contains
some entries that are more than 1023 bytes long, which is the largest
value that is safe to use with the many historical applications that
only allocate a 1024 byte termcap buffer (telnet, for example). If
you make sure that all of your programs allocate buffers of at least
2500 bytes, or let the termcap library do it by passing a NULL
pointer, then it is safe to install the new termcap file, as described
below.

You can give configure two special options:
--enable-install-termcap install the termcap data file
--with-termcap=FILE use data file FILE instead of /etc/termcap

Please report any bugs in this library to bug-gnu-emacs@prep.ai.mit.edu.
You can check which version of the library you have by using the RCS
`ident' command on libtermcap.a.
 
Looking for C libraries to write screen info using the terminfo system for compatibility.
The standard library is curses, or its (compatible) successor ncurses. They are supported everywhere and most text-mode user interfaces are written using them. They use termcap or terminfo, depending on what's available in your system.

Decades ago my employer only used specific terminals so we just used the escape sequences.
You can also use termcap or terminfo directly to get the correct escape sequences for your terminal.

Depends on what you want to do.
 
There are two things being mixed here.

Termcap and terminfo are two "database" formats for storing information about terminals. Termcap was just a big flat text file like /etc/termcap and a brief description of the escape sequences each terminal. Terminfo is a precompiled database with separate files for each terminal, and more details about each terminal.

There was a lightweight wrapper library for dealing with the termcap file called, confusingly enough, libtermcap. This originates with vi, I believe. So if it's just a matter of clearing the screen, positioning the cursor, etc., libtermcap, or its compatible successor libtinfo which is part of ncurses, would be all you need.

libcurses comes from SysV I think, and is more sophisticated than libtermcap, with fuller facilities to build what has come to be known as "TUIs". In particular I believe its original secret sauce was an off-screen buffer you would manipulate, and then a "make the screen look like this" call you could make, and it would consider the capabilities of the current terminal to determine the most efficient (smallest) set of escape sequences to send to change the screen.

Linux distributions used to come with a separate GNU libtermcap that used the termcap file, and libncurses that uses the terminfo database. All along, libncurses had the ability to emulate the libtermcap API and consult the terminfo database instead, so that there would be only one source of truth. At some point, the linux distros realized this, and deprecated termcap/libtermcap entirely, linking everything that uses termcap to ncurses (well, "libtinfo") instead.
 
Side note, a few Uniflex utilities use something a bit like curses that I can see references to when decompiling.

Code:
      v_posit(_vp,0,0);
      v_c_scr(_vp);
      v_flush(_vp);

I guess a precursor / Tektronix experiment.
 
Back
Top