RedGrittyBrick

The trouble with Terminals

Background

Dumb Terminals

Once upon a time, before personal computers, before microcomputers, there existed mainframe and minicomputers. These were big expensive things and the use of each one was typically shared by many people. more…

Standards

One of the dominant computer makers was the Digital Equipment Corporation, Known as DEC. I’m ignoring IBM who had their unique standards (3270). Their earliest terminal in widespread use was the VT52. This was superceded by the VT100 which did all the VT52 did and more. The VT100 inherited a lot of legacy features from the VT52. It still had a keyboard layout you’d not recognise from today’s PCs. more…

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. more …

Problems

Inconsistent implementations

If you look in /etc/termcap on a Linux system, you’ll see dozens of different entries for vt100 terminals. This is because nobody implements the whole of the vt100 spec and nothing but the vt100 spec. They all omit some things and add their own extensions.

This is fairly inevitable since the vt100 spec is both overly complex (who needs double-height characters?) and lacking (e.g. no support for pc-keyboard function keys and editing keys).

This also applies to ansi and ecma terminal definitions.

Keyboard layouts

The vt100 keyboard didn’t have keys F1 to F12. It did have keys labelled PF1 to PF4 above the numeric pad (where a PC has NumLock / * and -). Later DEC keyboards had different keys where a PC has Insert Delete Home End PgUp and PgDn. Some DEC keys were similar in name but differently placed.

vt100 keyboard

Many VT100 terminal emulation programs emulate the VT keyboard layout on a PC. This means that the key labelled End actually has the effect of PageUp. Unless you are a touch typist trained on a LK411 keyboard, this makes no sense.

Too many translations

When you are running an application and press a key, there are at least three different places where configuration can affect what happens:

  1. Terminal emulator configuration
  2. Termcap or Terminfo
  3. Application configuration

In the terminal emulator, you can often configure which physical key on the PC keyboard is mapped to key in the emulated terminal. For example, the default might be that PC NumLock is mapped to VT100 PF1. Then, when NumLock is pressed, the emulator sends a set of characters associated with PF1 (Escape O A).

In the termcap or terminfo files, you can specify what sequence of characters is mapped to a key in termcap or terminfo terminology. For example you could say k1=\EOA. The termcap capability-names (k1 etc) have been inconsistently extended by various manufacturers, so there are obsolete and ambiguous definitions. A termcap file from one vendor may not work very well on another manufacturers computer.

Some programming languages have their own concept of keys. For example the programmer might be able to state: “OPTION HELP-KEY (F1)” which might mean that pressing F1 should invoke an in-built help routine. The programming language defines F1 as the key labelled k1 in termcap. Some times programming languages define their own extensions to termcap or have inconsistent definitions. (e.g. the language says F1 is the key labelled k0 in termcap).

Too much configurability

Terminals had set-up screens where you could change many aspects of the terminal’s behaviour. You might be able to change the number of columns from 80 to 132; set it so that the cursor “wraps” to the start of the next line when a character is written to the last column on the screen.

The computer application often needed to know which settings were in effect. Some terminals provided a way of interrogating them about these settings. Some termcap files provide alternate definitions. e.g vt100-am for vt100 with auto-margins (line-wrap described above)

This makes it too easy to get a mismatch in terminal definition somewhere along the line.

The Escape key

The original definition of the Escape character said it was to be used to indicate that the following characters should be used to identify a special function to be performed.

Unfortunately, we have ended up with a key labelled Esc on the keyboard that transmits the Escape character. Windows users expect this to cancel the current task rather than prefix an character sequence that indicates a special function.

The Esc key and Escape character is also used by Unix programs such as vi, where it terminates input mode, returning to command mode.

This dual use means that the operating system has to wait after receiving an Escape to see if another character follows. Only timing can distinguish between Escape, “A” meaning the user pressed F1 meaning they want a help page displayed or they pressed Esc to end input mode and then pressed A to append text to the end of line.

This means that when I press F1 the response is immediate but when I press Esc there is a one second delay whilst the OS works out what key I pressed.

Terminal identification

There’s no standard way the OS can interrogate a serial terminal to ask it to identify itself (e.g. Wyse–50 vs vt102).

The escape sequence that asks a vt100 to send back its identifier may cause a different make of terminal to do something undesired (e.g. change language, go offline, etc).

Solution?

I sometimes wonder if someone should define a new, really simple and unambiguous terminal, that is easy to write an emulator for and which defines a really minimal set of features.

The problem is no-one will agree on the minimum necessary set of features.

Here’s my list: