Unix tty erase

the problem

It is a noted problem with Unix that it doesn't handle the two delete-like ASCII characters well. The normal Unix tty canonical mode line discipline insists on knowing which one the terminal will send for a normal backspacing delete operation; unfortunately, the mechanism by which this is configured is mainly used for setting user preferences, rather than for terminal type handling. This is, in fact, the only aspect of canonical mode processing that is dependent on the terminal type.

It's very difficult to get the configuration right. My shell setup has the best solution I can come up with from user space: a set of guesses that are usually right. Some people have tried to pick one character or the other, and proposed insisting that the terminal always send that one, but this isn't a workable solution because among the deployed base of terminals there are in fact many terminals that differ on this point and are not configurable.

the solution

My proposal to fix this is that canonical mode processing should by default accept both delete-like characters. This completely avoids the configuration problem, by making the canonical mode processing terminal-type-independent. This solution is also applicable to any other code that implements line editing, such as text editors and shell command line editors; for the moment it seems more important to me to fix the Unix kernels.

There are two basic approaches to accepting both delete-like characters in canonical mode. The first possibility is to have two configurable erase characters. FreeBSD already has this. There are two disadvantages to this approach: one is that userspace tools that don't know about the ERASE2 character may, in attempting to guess the right erase character, set ERASE to the same as the ERASE2 character, negating the advantage. The second is that it's difficult to add ERASE2 to a system that doesn't already have it: the syscall interface changes and the stty program has to change.

The solution that I propose involves no interface changes at all. I propose that the two well-known delete-like characters be treated specially thus: in canonical mode, if IEXTEN is on and the ERASE character is set to either ^H or ^?, then both ^H and ^? are treated as ERASE characters. The standard single-erase-character behaviour is followed if IEXTEN is off (which prohibits non-POSIX extended behaviour) or if the ERASE character is neither ^H or ^? (indicating that the user actually wants erase behaviour other than the usual use of the erase keys).

implementation

I've been attempting to get this proposal adopted in Linux.