Detect backspace by looking at termios VERASE and translate it into \177 (which

matches screen's behaviour if not its termcap/terminfo entry). The terminfo kbs
cap is often wrong or missing so it can't be used, and just assuming \177 may
be wrong.
pull/1/head
Nicholas Marriott 2009-07-26 21:42:08 +00:00
parent 55d8c01c33
commit 639fbe0392
5 changed files with 22 additions and 4 deletions

View File

@ -36,6 +36,9 @@ struct input_key_ent {
};
struct input_key_ent input_keys[] = {
/* Backspace key. */
{ KEYC_BSPACE, "\177", 0 },
/* Function keys. */
{ KEYC_F1, "\033OP", INPUTKEY_CTRL|INPUTKEY_XTERM },
{ KEYC_F2, "\033OQ", INPUTKEY_CTRL|INPUTKEY_XTERM },

View File

@ -57,7 +57,7 @@ struct {
{ "PPage", KEYC_PPAGE },
{ "Tab", '\011' },
{ "BTab", KEYC_BTAB },
{ "BSpace", '\177' },
{ "BSpace", KEYC_BSPACE },
/* Arrow keys. */
{ "Up", KEYC_UP },

View File

@ -70,7 +70,7 @@ mode_key_lookup_vi(struct mode_key_data *mdata, int key)
mdata->flags &= ~MODEKEY_EDITMODE;
return (MODEKEYCMD_NONE);
case '\010':
case '\177':
case KEYC_BSPACE:
return (MODEKEYCMD_BACKSPACE);
case '\011':
return (MODEKEYCMD_COMPLETE);
@ -84,7 +84,7 @@ mode_key_lookup_vi(struct mode_key_data *mdata, int key)
switch (key) {
case '\010':
case '\177':
case KEYC_BSPACE:
return (MODEKEYCMD_LEFT);
case KEYC_DC:
return (MODEKEYCMD_DELETE);
@ -151,7 +151,7 @@ mode_key_lookup_emacs(struct mode_key_data *mdata, int key)
{
switch (key) {
case '\010':
case '\177':
case KEYC_BSPACE:
return (MODEKEYCMD_BACKSPACE);
case '\004':
case KEYC_DC:

3
tmux.h
View File

@ -121,6 +121,9 @@ enum key_code {
/* Mouse key. */
KEYC_MOUSE = 0x1000,
/* Backspace key. */
KEYC_BSPACE,
/* Function keys. */
KEYC_F1,
KEYC_F2,

View File

@ -20,6 +20,8 @@
#include <sys/time.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include "tmux.h"
@ -235,6 +237,7 @@ tty_keys_next(struct tty *tty, int *key, u_char *mouse)
struct timeval tv;
char *buf;
size_t len, size;
cc_t bspace;
buf = BUFFER_OUT(tty->in);
len = BUFFER_USED(tty->in);
@ -245,6 +248,15 @@ tty_keys_next(struct tty *tty, int *key, u_char *mouse)
/* If a normal key, return it. */
if (*buf != '\033') {
*key = buffer_read8(tty->in);
/*
* Check for backspace key using termios VERASE - the terminfo
* kbs entry is extremely unreliable, so cannot be safely
* used. termios should have a better idea.
*/
bspace = tty->tio.c_cc[VERASE];
if (bspace != _POSIX_VDISABLE && *key == bspace)
*key = KEYC_BSPACE;
goto found;
}