As I understand it, when typing characters in a terminal emulator they appear because they are "echoed". We imagine that the terminal is a separate device communicating with the computer via a two-way channel, and each key typed doesn't update the screen immediately, but appears when it is sent back from the computer.
My question is how it is possible for the backspace key, or whatever key is set to "erase" with stty
, to appear to erase a character on the screen. If in an xterm
I do
$ stty erase x
$ cat -
aaaaaaaaaax
the last x
I type appears to erase the last a
. However if this were a real terminal, separate from the computer, it wouldn't have any way of knowing what the stty erase
character was. The only way I would expect to get this behaviour would be if the erase character was ^H
and it was echoed, and the terminal interpreted this as a special control character telling it to erase the character before the cursor.
Is this a peculiarity of terminal emulators, where they "cheat" and look up what the stty erase
character is?