summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-06-06 19:00:14 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-06-06 19:00:14 +0000
commit38965f5299b268b94c338ebb68e4a7f8aa330325 (patch)
tree4bc3c3c009d427d06b6bbc529b470e14a741932a /usr.bin
parente63e697bedbb9649d9bb7b924b7b17fe2f675c6c (diff)
Use a macro-based mask for obtaining a key or modifier-set from the
combination. Display C-@, etc, as C-Space, in list-keys. By Micah Cowan.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/key-string.c13
-rw-r--r--usr.bin/tmux/tmux.h6
-rw-r--r--usr.bin/tmux/window-copy.c8
3 files changed, 20 insertions, 7 deletions
diff --git a/usr.bin/tmux/key-string.c b/usr.bin/tmux/key-string.c
index 07ebb20cf11..79736f1312b 100644
--- a/usr.bin/tmux/key-string.c
+++ b/usr.bin/tmux/key-string.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: key-string.c,v 1.17 2010/06/05 15:51:53 nicm Exp $ */
+/* $OpenBSD: key-string.c,v 1.18 2010/06/06 19:00:13 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -184,6 +184,15 @@ key_string_lookup_key(int key)
*out = '\0';
+ /*
+ * Special case: display C-@ as C-Space. Could do this below in
+ * the (key >= 0 && key <= 32), but this way we let it be found
+ * in key_string_table, for the unlikely chance that we might
+ * change its name.
+ */
+ if ((key & KEYC_MASK_KEY) == 0)
+ key = ' ' | KEYC_CTRL | (key & KEYC_MASK_MOD);
+
/* Fill in the modifiers. */
if (key & KEYC_CTRL)
strlcat(out, "C-", sizeof out);
@@ -191,7 +200,7 @@ key_string_lookup_key(int key)
strlcat(out, "M-", sizeof out);
if (key & KEYC_SHIFT)
strlcat(out, "S-", sizeof out);
- key &= ~(KEYC_CTRL|KEYC_ESCAPE|KEYC_SHIFT);
+ key &= KEYC_MASK_KEY;
/* Try the key against the string table. */
for (i = 0; i < nitems(key_string_table); i++) {
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 905e018dd88..00ac0374b99 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.224 2010/06/05 16:47:11 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.225 2010/06/06 19:00:13 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -111,6 +111,10 @@ extern char **environ;
#define KEYC_SHIFT 0x8000
#define KEYC_PREFIX 0x10000
+/* Mask to obtain key w/o modifiers */
+#define KEYC_MASK_MOD (KEYC_ESCAPE|KEYC_CTRL|KEYC_SHIFT|KEYC_PREFIX)
+#define KEYC_MASK_KEY (~KEYC_MASK_MOD)
+
/* Other key codes. */
enum key_code {
/* Mouse key. */
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index 0d1c66ca951..351ff2b529e 100644
--- a/usr.bin/tmux/window-copy.c
+++ b/usr.bin/tmux/window-copy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-copy.c,v 1.58 2010/06/05 15:49:48 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.59 2010/06/06 19:00:13 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -367,7 +367,7 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key)
if (data->inputtype == WINDOW_COPY_JUMPFORWARD
|| data->inputtype == WINDOW_COPY_JUMPBACK) {
/* Ignore keys with modifiers. */
- if ((key & 0xff00) == 0) {
+ if ((key & KEYC_MASK_MOD) == 0) {
data->jumpchar = key;
if (data->inputtype == WINDOW_COPY_JUMPFORWARD) {
for (; np != 0; np--)
@@ -627,7 +627,7 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key)
*data->inputstr = '\0';
goto input_on;
case MODEKEYCOPY_STARTNUMBERPREFIX:
- key &= 0xff;
+ key &= KEYC_MASK_KEY;
if (key >= '0' && key <= '9') {
data->inputtype = WINDOW_COPY_NUMERICPREFIX;
data->numprefix = 0;
@@ -741,7 +741,7 @@ window_copy_key_numeric_prefix(struct window_pane *wp, int key)
struct window_copy_mode_data *data = wp->modedata;
struct screen *s = &data->screen;
- key &= 0xff;
+ key &= KEYC_MASK_KEY;
if (key < '0' || key > '9')
return 1;