Friday, September 16, 2005

Terminal Characters

stty erase ^H

tells the terminal driver upon which character it should perform
the "bacward erase character" operation in its built-in line

That built-in line editor is only used when the terminal is in
canonical mode, ie when the terminal sends the data to the
reading application only when you press enter.

Typically, neither bash nor vim use that canonical mode as they
need to be able to get each typed character as soon as they are
typed. But vim may want to query the terminal driver to find out
what character is supposed to be the backspace character (if
it's good for the terminal builtin editor, then it will be good
for vim).

bash doesn't care. It treats both ^? and ^H as a backspace

What I think is that when you press <Backspace>, you get a ^?
character. So, you should instruct your terminal driver (and
indirectly vim) that "erase" is ^? with stty erase '^?'.

> Now I am using an application, it has its shell, in pressing UP
> arrow key, I see ^]]A, I look through manpage of stty, I do not see how
> to redefine UP arrow key.

stty is not to redefine keys, it's to tell the terminal driver
on which received character it should perform its special
operations. It works only for single characters. ^[[A is a
sequence of 3 characters.

And the builtin terminal line editor has few operations you can
map a key to, mainly "backward erase character", (^H, ^?)
"backward erase word" (^W), "kill line" (^U), "interrupt" (^C),
"quit" (^\)...

If you need a more complex line editor, then you need to
implement one just as bash (readline) or vim do.
That means, leave the canon mode stty -icanon. Tell the terminal
you want to receive characters as soon as they are typed: stty
min 1 time 0, (you may want to disable the signal keys as well
stty -isig, or the automatic conversion of CR into NL stty
-icrnl... stty raw may even be what you want) read characters
one at a time (c=$(dd bs=1 count=1 2> /dev/null)) then do the
processing for each character: if it's a ^[, then read the next
one, then if it's a "[", read the next one, then if it's a "A"
then perform whatever you want to be done on the pressing of the
Up key.


>> Hi,
>> I am using BASH 2.05 on Red Hat Linux, I have the following command
>> in .bashrc,

>> stty erase "^H"

> The linux console and xterm both produce a DEL character (^?) when
> you hit the big backspace key.


For xterm, it depends on the implementation on the default value
of the terminal driver and on the configuration.


Post a Comment

<< Home