Trouble with Curses
Duncan MacGregor
duncan at sysint.uucp
Wed Nov 14 17:16:35 AEST 1990
In a recent posting, "draper" (sorry, I lost track of the precise article)
complained that characters read through the curses library disappeared after
an ESC (escape, octal 033) character was read. In essence, the 'C' code was
expecting an ESC followed by the letter 'e' to indicate "exit from the system".
The problem lies not in curses but (I believe) in termcap. I know the
problem exists in "terminfo", which is the replacement for termcap in System V
Rel. 2 and all descendant systems; I believe it was inherited (or should I
say inherent?) from termcap.
The problem is caused by the necessity of dealing with "function keys",
"cursor keys", and other symbolic keys on the keyboard. When one of these keys
is pressed, the terminal usually sends a STRING of characters to the host. In
almost every case, the first character of such a string is ESC, to warn the host
(and thus termcap/terminfo) that a function key was pressed. These strings are
therefore often known as "escape sequences".
When an ESC character is received from the terminal, however, termcap or
terminfo can NOT assume that a function/cursor key was pressed; it is perfectly
possible (as in the case of ESC+'e' above) that the user typed the ESC key by
itself. The solution for this can only be described as kludgy (I think Henry
Spencer cited it recently with some rather uncomplementary prose). When the
ESC is received, a timer is started. If the timer expires (after ~1/10 sec.)
and another character has NOT been received, the ESC character is assumed to
have come from the ESC key, and not from a function key. If a character
arrives before the expiration, it is added (as part of an escape sequence!) and
the timer restarted. While it is possible to change the length of time before
the timer expires in the termcap/terminfo source code (it is actually using the
UNIX terminal driver for this), a fast typist can easily beat most such settings
of the timer. The letter 'e', therefore, since it is typed right after an ESC,
may be grabbed as part of a supposed "escape sequence" string. Even if that
does not happen, there IS a delay before the timer expires. In terminfo, if
the characters after ESC do not correspond with a known key for the current
terminal type, it will re-interpret the string as separate characters (I think).
This certainly seems to be happening with the example given by "draper".
Some newer terminals (eg. the DEC vt200) can use a special 8-bit character
to mark the beginning of "escape sequence" strings if you use the terminal's
"8-bit" mode. Alas, there is NO support for 8-bit characters in terminfo or
termcap (as far as I know). The cryptic notation used in the termcap and term-
info databases cannot support it either. Just a suggestion: maybe somebody
could develop a version of termcap that would allow macros to be freely used
in declaring strings or numbers? That might make it MUCH easier to represent
8-bit characters that start "escape sequence" strings.
Hope this is helpful ...
--
Duncan MacGregor Systems Interface Inc.
UUCP: uunet!mitel!cunews!cognos!sysint!duncan || duncan at sysint.UUCP
#include <std/disclaim.h>;
Life is a zig-zag; too many people zig as always - they shoulda zagged. (Anon)
More information about the Comp.lang.c
mailing list