RedGrittyBrick

Programming for Terminals

Programming

It would have been pretty tedious to code variations in each applications for each terminal: “order entry for vt52”, “order entry for vt100”, “order entry for Wyse 50” and so on.

So I guess, people wrote terminal handling libraries to insulate the actual application coding from whatever terminal was in use. The “curses” library must have arisen from this. Curses defines abstract functions for moving the cursor around. It translates these into the control codes that have to be sent to a specific type of terminal.

On Unix, the library finds out what sort of terminal from an environment variable “TERM” that is set in the login scripts.

Termcap and Terminfo

having worked out what sort of terminal is being dealt with, the program (curses library) has to work out what characters need to be sent to the terminal to cause it to do various useful things such as move the cursor, clear the screen and so on

The termcap database was invented to provide a list of terminals giving, for each terminal, a list of control codes. This meant that terminal functions had to be given abstract “capability names” such as “so” for Begin Standout Mode (e.g. reverse video).

The termcap database was one text file. This became large and unwieldy. It was superceded by the terminfo database. This has one file per terminal organised in a directory hierarchy. terminfo files are binary, not text. terminfo uses different capability names which are longer (and so marginally more mnemonic)

The O’Reilly book “Termcap and Terminfo” is a good source of information on this subject.