Subject: Re: Where is the Color ?
To: None <netbsd-help@NetBSD.org>
From: James K. Lowden <jklowden@schemamania.org>
List: netbsd-help
Date: 03/22/2004 19:57:47
On Mon, 22 Mar 2004, "Zafer Aydogan" <zafer@gmx.org> wrote:
> 
> I'm using Putty to connect to my NetBSD Server.
> I don't know how to get the Function Keys , Keypad, Backspace Key & Home
> Key work well.

It's ridiculously hard, and requires no programming.  There are basically
two components:

1.  What byte sequence your terminal emulation generates when you press a
key.  
2.  What application/library is reading those byte sequences.  

IOW, there's no universal "work well".  There's one file to configure
bash, another for vi, etc.  It's crummy, but at least it's universally
crummy.  :-(

First stop is to know your emulator.  To find out what byte sequence is
being used, try something like this:

	$ hexdump -C

to make hexdump(1) read your keystrokes.  Now press <home> <return>
<ctrl-D>, and you'll see something like this:

	^[[H

These are the terminal's representation of the bytes you sent.  Then we
have hexdump's output:

00000000  1b 5b 48 0a                                       |.[H.|
00000004

Four bytes: ESC [ H <newline>.  The first three are what was sent when I
pressed <home>.  I'm using the xterm that comes with NetBSD.  You'll want
to make a little list of what Putty sends for the keys you care about.  

Next is to RTFM for the thing you're trying to use.  The bash shell, for
instance, relies on the GNU readline library to read the terminal, which
supports ~/inputrc.  Mine looks like this:

$ cat ~/.inputrc 
"\e[3~": delete-char            # [delete]
"\e[H": beginning-of-line       # [home]
"\e[F": end-of-line                     # [end]
"\e[5D": backward-word          # ctrl+[left arrow]
"\e[5C": forward-word           # ctrl+[right arrow]

As you can see, inputrc uses "\e" to mean escape, and I've mapped <home>
to readline's beginning-of-line command, so it does what ^A does.  

Hope that's of some use.

--jkl