summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2009-12-02 15:06:35 +0000
committerTiago Cunha <tcunha@gmx.com>2009-12-02 15:06:35 +0000
commit97350cd883590a3dfaa3307446f3ca979134533d (patch)
tree4e637590168625bac425b3650a9730fac6dbdf0b
parent5081d7333064aecc188ffed1484f46bb2123b145 (diff)
Sync OpenBSD patchset 575:
Handle partial xterm function key sequences.
-rw-r--r--tmux.h4
-rw-r--r--tty-keys.c11
-rw-r--r--xterm-keys.c39
3 files changed, 35 insertions, 19 deletions
diff --git a/tmux.h b/tmux.h
index 7466f7c9..ca9c762a 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.526 2009-11-28 14:57:59 tcunha Exp $ */
+/* $Id: tmux.h,v 1.527 2009-12-02 15:06:34 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1646,7 +1646,7 @@ void input_mouse(struct window_pane *, struct mouse_event *);
/* xterm-keys.c */
char *xterm_keys_lookup(int);
-int xterm_keys_find(const char *, size_t, size_t *);
+int xterm_keys_find(const char *, size_t, size_t *, int *);
/* colour.c */
void colour_set_fg(struct grid_cell *, int);
diff --git a/tty-keys.c b/tty-keys.c
index 82a23a0c..78b267b3 100644
--- a/tty-keys.c
+++ b/tty-keys.c
@@ -1,4 +1,4 @@
-/* $Id: tty-keys.c,v 1.50 2009-11-28 14:51:37 tcunha Exp $ */
+/* $Id: tty-keys.c,v 1.51 2009-12-02 15:06:35 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -472,12 +472,15 @@ tty_keys_next(struct tty *tty)
goto partial_key;
}
-
/* Not found. Try to parse a key with an xterm-style modifier. */
- key = xterm_keys_find(buf, len, &size);
- if (key != KEYC_NONE) {
+ switch (xterm_keys_find(buf, len, &size, &key)) {
+ case 0: /* found */
evbuffer_drain(tty->event->input, size);
goto handle_key;
+ case -1: /* not found */
+ break;
+ case 1:
+ goto partial_key;
}
/* Skip the escape. */
diff --git a/xterm-keys.c b/xterm-keys.c
index c18e26f4..a191471a 100644
--- a/xterm-keys.c
+++ b/xterm-keys.c
@@ -1,4 +1,4 @@
-/* $Id: xterm-keys.c,v 1.3 2009-11-08 23:33:57 tcunha Exp $ */
+/* $Id: xterm-keys.c,v 1.4 2009-12-02 15:06:35 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -85,22 +85,28 @@ struct xterm_keys_entry xterm_keys_table[] = {
{ KEYC_DC, "\033[3;_~" },
};
-/* Match key against buffer, treating _ as a wildcard. */
+/*
+ * Match key against buffer, treating _ as a wildcard. Return -1 for no match,
+ * 0 for match, 1 if the end of the buffer is reached (need more data).
+ */
int
xterm_keys_match(const char *template, const char *buf, size_t len)
{
size_t pos;
- if (len == 0 || len < strlen(template))
+ if (len == 0)
return (0);
pos = 0;
do {
if (*template != '_' && buf[pos] != *template)
- return (0);
+ return (-1);
} while (pos++ != len && *++template != '\0');
- return (1);
+ if (*template != '\0') /* partial */
+ return (1);
+
+ return (0);
}
/* Find modifiers based on template. */
@@ -131,22 +137,29 @@ xterm_keys_modifiers(const char *template, const char *buf, size_t len)
return (0);
}
-/* Lookup key from buffer against table. */
+/*
+ * Lookup key from a buffer against the table. Returns 0 for found (and the
+ * key), -1 for not found, 1 for partial match.
+ */
int
-xterm_keys_find(const char *buf, size_t len, size_t *size)
+xterm_keys_find(const char *buf, size_t len, size_t *size, int *key)
{
struct xterm_keys_entry *entry;
u_int i;
for (i = 0; i < nitems(xterm_keys_table); i++) {
entry = &xterm_keys_table[i];
- if (xterm_keys_match(entry->template, buf, len))
- break;
+ switch (xterm_keys_match(entry->template, buf, len)) {
+ case 0:
+ *size = strlen(entry->template);
+ *key = entry->key;
+ *key |= xterm_keys_modifiers(entry->template, buf, len);
+ return (0);
+ case 1:
+ return (1);
+ }
}
- if (i == nitems(xterm_keys_table))
- return (KEYC_NONE);
- *size = strlen(entry->template);
- return (entry->key | xterm_keys_modifiers(entry->template, buf, len));
+ return (-1);
}
/* Lookup a key number from the table. */