Tuesday, October 16, 2007

MacOSX + Linux + stty + terminfo + X11 + xterm + screen = backspace is teh suck

I got the backspace key to work across machines and with various programs, but it wasn't easy. Every keystroke goes through a ton of different layers that can remap keys in arbitrary and usually broken ways:
  • MacOS keyboard maps
  • X11 xmodmap
  • xterm VT100 widget X resources (from .Xresources through xrdb)
  • ssh
  • Linux kernel terminal driver (through stty)
  • terminfo (chosen via the $TERM environment variable, used by libraries such as curses)
  • GNU screen (the "bindkey" command in .screenrc)
  • the actual application:
    • shell keymaps (the "bindkey" builtin command in zsh, configured via .zshrc)
    • emacs keymaps (some .el file)
Here's the various settings I changed to get this working consistently:
In X11.app's X11 Preferences, "Use the system keyboard layout" is checked, "Enable keyboard shortcuts under X11" is unchecked.
In ~/.Xresources on my MacBook:
*locale: UTF-8
XTerm*metaSendsEscape: true
XTerm*backarrowKey: false
XTerm*backarrowKeyIsErase: false
XTerm*termName: xterm-color
In ~/.zshrc:
bindkey "^?" backward-delete-char
Changed some settings in ~/.terminfo/x/xterm-color in Linux to match the mac's xterm resources:
bce@, # mac's xterm is too old to support back color erase
kbs=\177, # backarrow key sends ^?
kdch1=\E[3~, # forward delete key
Wasn't that easy?

No comments: