summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-07-26 21:42:08 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-07-26 21:42:08 +0000
commit639fbe03922924b70fca7860845590e8c3aa927a (patch)
tree105603ab6f5b743e0faef50913c3b6ac7e02af3d
parent55d8c01c339db6dd66ed85ce3da5273632da6ca5 (diff)
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.
-rw-r--r--input-keys.c3
-rw-r--r--key-string.c2
-rw-r--r--mode-key.c6
-rw-r--r--tmux.h3
-rw-r--r--tty-keys.c12
5 files changed, 22 insertions, 4 deletions
diff --git a/input-keys.c b/input-keys.c
index 0afe6e47..30e2be05 100644
--- a/input-keys.c
+++ b/input-keys.c
@@ -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 },
diff --git a/key-string.c b/key-string.c
index 23aa6ad7..5c8ce5b3 100644
--- a/key-string.c
+++ b/key-string.c
@@ -57,7 +57,7 @@ struct {
{ "PPage", KEYC_PPAGE },
{ "Tab", '\011' },
{ "BTab", KEYC_BTAB },
- { "BSpace", '\177' },
+ { "BSpace", KEYC_BSPACE },
/* Arrow keys. */
{ "Up", KEYC_UP },
diff --git a/mode-key.c b/mode-key.c
index 9db6d86c..9e5720eb 100644
--- a/mode-key.c
+++ b/mode-key.c
@@ -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:
diff --git a/tmux.h b/tmux.h
index 159711e7..046e6a19 100644
--- a/tmux.h
+++ b/tmux.h
@@ -121,6 +121,9 @@ enum key_code {
/* Mouse key. */
KEYC_MOUSE = 0x1000,
+ /* Backspace key. */
+ KEYC_BSPACE,
+
/* Function keys. */
KEYC_F1,
KEYC_F2,
diff --git a/tty-keys.c b/tty-keys.c
index 5e207aa6..f25dc169 100644
--- a/tty-keys.c
+++ b/tty-keys.c
@@ -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;
}