Console programs typically use curses or one of its successors to build the sorts of text user interfaces you're talking about. (There are other libraries of this sort, but it's not important to list them all here.)
These libraries use one of two databases, called
terminfo. (This is one of the many BSD vs. AT&T differences you still find in modern Unix systems.) These databases contain maps that tell how to control the many terminal types. The vast majority of the terminal types you'll find defined in these databases didn't survive the days of real terminals, and so are now only of historical interest.
What's survived, and are used by programs like
minicom and GUI "terminal" programs like
xterm, GNOME Terminal, the OS X Terminal, etc., are a few common standards:
ANSI X3.64: A standard for controlling "glass terminals" — as opposed to teletypes — it is based on special sequences of characters which the remote terminal interprets. For instance, if the Unix box wants to tell the terminal to move its cursor to the upper left corner of the screen, it sends the characters
H. The first two characters tell the terminal to expect a control sequence, the 1s are the row and column, and
H is the command meaning "move cursor". Unix programs don't embed these escape sequences, it's all handled by the libraries mentioned above.
Trivia: many PC BBSes used ANSI codes, too. (Still do, actually.)
DEC VT100: A variant of the ANSI terminal standard, it became popular enough that it's still supported by most terminal programs in some form. Sometimes you see this called the VT102 protocol, that being a later cost-reduced — and therefore more popular — version of the VT100 plus all available expansion options built-in.
The DEC terminal protocols are a backwards-compatible series, extending from the first ANSI-compatible model introduced in 1978 (the VT100) up through the VT500 series models you can still buy from Boundless Technologies, who bought the terminal business from DEC in 1995.
A typical terminal emulator program is something of a mongrel, and doesn't emulate one particular terminal model exactly. It might support 96% of all DEC VT escape sequences up through the VT320, yet also support extensions like ANSI color (a VT525 feature) and an arbitrary number of rows and columns. The 4% of codes it doesn't understand may not be missed if your programs don't need those features, even though you've told
curses (or whatever) that you want programs using it to use the VT320 protocol. Such a program might advertise itself as VT320 compatible, then, even though, strictly speaking, it is not.
xterm: A kind of amalgam of ANSI and the VT-whatever standards. Whenever you're using a GUI terminal emulator like xterm or one of its derivatives, you're usually also using the xterm terminal protocol, typically the more modern
Linux: The Linux console also uses an extended variant of the ANSI terminal protocol, in the same spirit as the
xterm protocols. Most of its extensions have to do with the differences between a PC and a glass terminal. For example, the IBM keyboard has some keys not on a DEC VT-whatever. (And vice versa.)
Like Linux, some Unix systems have their own console terminal protocol, too. There's the
scoansi ANSI X3.64 variant for SCO Unixes, for example.
Wyse: A company, still around, that got started making glass terminals back in the minicomputer days. Although Wyse terminals were able to emulate the VT100 and other popular terminal protocols, they also had their own native codes. I mention it only because you still sometimes see programs that know these codes.
You can find out which terminal standard you're asking libraries like
curses to use by looking at the
TERM environment variable:
$ echo $TERM
ssh to another system, the
TERM variable is carried along so the remote Unix box knows how to communicate with your local terminal.
Because so many of these protocols are ANSI X3.64 variants, and because the ubiquitous ASCII and UTF-8 character coding standards take care of so much else, an incorrect
TERM variable isn't typically catastrophic. Things that tend to break are extended keys like Home and Page Up, Alt-whatever key combinations, and typographical display features like color, boldface, etc.