Exploring terminfo

Eli the Bearded * at eli.users.panix.com
Tue Jan 19 16:54:47 EST 2021


In comp.lang.python, Greg Ewing  <greg.ewing at canterbury.ac.nz> wrote:
> On 18/01/21 3:34 am, Alan Gauld wrote:
>> The problem is terminfo is not really part of curses.
>> Curses is built on top of terminfo.
> As far as I can tell from the man pages, terminfo itself
> is just a file format. The only programmatic interfaces I
> can find for it *are* part of curses:

Putting my Unix hat on, curses is a "friendly" library around creating
text-windowed applications. Programs like mutt use curses rather than
raw terminal operations, programs like vi use raw terminal operations.
Either curses or raw terminal operations will (should) consult a
terminal capabilities database to figure out what can be done and how to
do it. The two competing database formats for that are termcap and
terminfo, where terminfo is the newer, better one.

Termcap used a single large text file for all terminals types.
Terminfo uses a directory tree full of small files, one per type.

I'm pretty sure both include the ability to say something along the
lines of "start with this one terminal, and then change these bits".
So that starts to get complicated without a library. Or maybe I'm wrong,
and vi uses curses. I'm not really sure how vi reads the term info files.

Okay, checking the source to the only vi I have lying around[*], it uses
a few curses calls, apparently only these:

    int tgetent(char *bp, const char *name);
    int tgetflag(char *id);
    int tgetnum(char *id);
    char *tgetstr(char *id, char **area);
    char *tgoto(const char *cap, int col, int row);
    int tputs(const char *str, int affcnt, int (*putc)(int));

My local manpage calles this set the "direct curses interface to the
terminfo capability database" whereas things I think of as "curses"
programs use calls like:

    WINDOW *initscr(void);
    int cbreak(void);
    int start_color(void);
    int noecho(void);
    int move(int y, int x);
    int attr_set(attr_t attrs, short pair, void *opts);
    int getch(void);
    int addch(const chtype ch);
    int printw(const char *fmt, ...);

The vi method relies on the programmer knowing what attributes are
wanted and how to use them, and how to use alternatives when the
first choices aren't provided. The curses method relies on the programmer
knowing which of a hundred different library functions to use for any
given output. :^)

[*] It's ex-1.1, an "heirloom" source package that has possibly been
    brushed up just enough to compile on a modern system. ex-1.1 is by
    most reckoning, the first vi. It won't start in vi mode though, you
    need to run ex, then begin the visual mode. It is recongizable as vi
    to me, but a somewhat different experience.

Elijah
------
has modified C curses programs, but not written one from scratch


More information about the Python-list mailing list