summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2017-01-25 14:24:55 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2017-01-25 14:24:55 +0000
commit0bfed3f3bb1d686425b146c317a512fee93a4813 (patch)
treea819052cf59f18afabdbecb02d5e2ea1f10e11f8 /usr.bin
parentd55df4d24388ccf6e6059dce10edf06602ca2abf (diff)
If xterm-keys is on, use xterm(1) style keys for Home and End as well as
modified keys.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/input-keys.c12
-rw-r--r--usr.bin/tmux/tmux.16
-rw-r--r--usr.bin/tmux/tmux.h4
-rw-r--r--usr.bin/tmux/xterm-keys.c47
4 files changed, 45 insertions, 24 deletions
diff --git a/usr.bin/tmux/input-keys.c b/usr.bin/tmux/input-keys.c
index da9a74cd991..9c865597136 100644
--- a/usr.bin/tmux/input-keys.c
+++ b/usr.bin/tmux/input-keys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: input-keys.c,v 1.56 2016/10/03 22:52:11 nicm Exp $ */
+/* $OpenBSD: input-keys.c,v 1.57 2017/01/25 14:24:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -158,6 +158,7 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
char *out;
key_code justkey;
struct utf8_data ud;
+ int mode;
log_debug("writing key 0x%llx (%s) to %%%u", key,
key_string_lookup_key(key), wp->id);
@@ -194,8 +195,9 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
* Then try to look this up as an xterm key, if the flag to output them
* is set.
*/
+ mode = wp->screen->mode;
if (options_get_number(wp->window->options, "xterm-keys")) {
- if ((out = xterm_keys_lookup(key)) != NULL) {
+ if ((out = xterm_keys_lookup(key, mode)) != NULL) {
bufferevent_write(wp->event, out, strlen(out));
free(out);
return;
@@ -206,11 +208,9 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
for (i = 0; i < nitems(input_keys); i++) {
ike = &input_keys[i];
- if ((ike->flags & INPUTKEY_KEYPAD) &&
- !(wp->screen->mode & MODE_KKEYPAD))
+ if ((ike->flags & INPUTKEY_KEYPAD) && (~mode & MODE_KKEYPAD))
continue;
- if ((ike->flags & INPUTKEY_CURSOR) &&
- !(wp->screen->mode & MODE_KCURSOR))
+ if ((ike->flags & INPUTKEY_CURSOR) && (~mode & MODE_KCURSOR))
continue;
if ((key & KEYC_ESCAPE) && (ike->key | KEYC_ESCAPE) == key)
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index c980b8f9281..8daef3bcfb3 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.530 2017/01/24 21:50:22 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.531 2017/01/25 14:24:54 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: January 24 2017 $
+.Dd $Mdocdate: January 25 2017 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -2470,7 +2470,7 @@ interactive menu when required.
.It Ic terminal-overrides[] Ar string
Allow terminal descriptions read using
.Xr terminfo 5
-to be overriden.
+to be overridden.
Each entry is a colon-separated string made up of a terminal type pattern
(matched using
.Xr fnmatch 3 )
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 3d5fb8ea14c..d9e6580de9f 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.706 2017/01/24 21:50:23 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.707 2017/01/25 14:24:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1888,7 +1888,7 @@ void input_parse(struct window_pane *);
void input_key(struct window_pane *, key_code, struct mouse_event *);
/* xterm-keys.c */
-char *xterm_keys_lookup(key_code);
+char *xterm_keys_lookup(key_code, int);
int xterm_keys_find(const char *, size_t, size_t *, key_code *);
/* colour.c */
diff --git a/usr.bin/tmux/xterm-keys.c b/usr.bin/tmux/xterm-keys.c
index 577e38fc7d2..8d216c028fa 100644
--- a/usr.bin/tmux/xterm-keys.c
+++ b/usr.bin/tmux/xterm-keys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xterm-keys.c,v 1.19 2016/10/03 22:52:11 nicm Exp $ */
+/* $OpenBSD: xterm-keys.c,v 1.20 2017/01/25 14:24:54 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -50,7 +50,17 @@ struct xterm_keys_entry {
const char *template;
};
-static const struct xterm_keys_entry xterm_keys_table[] = {
+static const struct xterm_keys_entry xterm_keys_standard[] = {
+ { KEYC_HOME, "\033[H" },
+ { KEYC_END, "\033[F" },
+};
+
+static const struct xterm_keys_entry xterm_keys_cursor[] = {
+ { KEYC_HOME, "\033OH" },
+ { KEYC_END, "\033OF" },
+};
+
+static const struct xterm_keys_entry xterm_keys_modified[] = {
{ KEYC_F1, "\033[1;_P" },
{ KEYC_F1, "\033O1;_P" },
{ KEYC_F1, "\033O_P" },
@@ -189,8 +199,8 @@ xterm_keys_find(const char *buf, size_t len, size_t *size, key_code *key)
int matched;
key_code modifiers;
- for (i = 0; i < nitems(xterm_keys_table); i++) {
- entry = &xterm_keys_table[i];
+ for (i = 0; i < nitems(xterm_keys_modified); i++) {
+ entry = &xterm_keys_modified[i];
matched = xterm_keys_match(entry->template, buf, len, size,
&modifiers);
@@ -205,10 +215,10 @@ xterm_keys_find(const char *buf, size_t len, size_t *size, key_code *key)
/* Lookup a key number from the table. */
char *
-xterm_keys_lookup(key_code key)
+xterm_keys_lookup(key_code key, int mode)
{
- const struct xterm_keys_entry *entry;
- u_int i;
+ const struct xterm_keys_entry *table, *entry;
+ u_int items, i;
key_code modifiers;
char *out;
@@ -224,21 +234,32 @@ xterm_keys_lookup(key_code key)
* If the key has no modifiers, return NULL and let it fall through to
* the normal lookup.
*/
- if (modifiers == 1)
- return (NULL);
+ if (modifiers != 1) {
+ table = xterm_keys_modified;
+ items = nitems(xterm_keys_modified);
+ } else {
+ if (mode & MODE_KCURSOR) {
+ table = xterm_keys_cursor;
+ items = nitems(xterm_keys_cursor);
+ } else {
+ table = xterm_keys_standard;
+ items = nitems(xterm_keys_standard);
+ }
+ }
/* Otherwise, find the key in the table. */
key &= ~(KEYC_SHIFT|KEYC_ESCAPE|KEYC_CTRL);
- for (i = 0; i < nitems(xterm_keys_table); i++) {
- entry = &xterm_keys_table[i];
+ for (i = 0; i < items; i++) {
+ entry = &table[i];
if (key == entry->key)
break;
}
- if (i == nitems(xterm_keys_table))
+ if (i == items)
return (NULL);
/* Copy the template and replace the modifier. */
out = xstrdup(entry->template);
- out[strcspn(out, "_")] = '0' + modifiers;
+ if (modifiers != 1)
+ out[strcspn(out, "_")] = '0' + modifiers;
return (out);
}