summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2017-06-23 15:36:52 +0000
committernicm <nicm>2017-06-23 15:36:52 +0000
commit95ed7d48c84198da0ec4b1b9b5de9358a47da753 (patch)
tree5b6515359ef39b43aae547292172ce20a17e160b
parenta67df177634f5ff3f6a24598d4016f61a794af62 (diff)
Add user-keys option to allow user-defined keys to be set, from Dan
Aloni.
-rw-r--r--cmd-set-option.c6
-rw-r--r--key-string.c10
-rw-r--r--options-table.c7
-rw-r--r--tmux.112
-rw-r--r--tmux.h4
-rw-r--r--tty-keys.c14
6 files changed, 50 insertions, 3 deletions
diff --git a/cmd-set-option.c b/cmd-set-option.c
index d8539ee7..02504d5c 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -240,6 +240,12 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
TAILQ_FOREACH(loop, &clients, entry)
server_client_set_key_table(loop, NULL);
}
+ if (strcmp(name, "user-keys") == 0) {
+ TAILQ_FOREACH(loop, &clients, entry) {
+ if (loop->tty.flags & TTY_OPENED)
+ tty_keys_build(&loop->tty);
+ }
+ }
if (strcmp(name, "status") == 0 ||
strcmp(name, "status-interval") == 0)
status_timer_start_all();
diff --git a/key-string.c b/key-string.c
index e1413a15..d630d778 100644
--- a/key-string.c
+++ b/key-string.c
@@ -110,12 +110,16 @@ static const struct {
static key_code
key_string_search_table(const char *string)
{
- u_int i;
+ u_int i, user;
for (i = 0; i < nitems(key_string_table); i++) {
if (strcasecmp(string, key_string_table[i].string) == 0)
return (key_string_table[i].key);
}
+
+ if (sscanf(string, "User%u", &user) == 1 && user < KEYC_NUSER)
+ return (KEYC_USER + user);
+
return (KEYC_UNKNOWN);
}
@@ -265,6 +269,10 @@ key_string_lookup_key(key_code key)
return ("MouseMoveStatus");
if (key == KEYC_MOUSEMOVE_BORDER)
return ("MouseMoveBorder");
+ if (key >= KEYC_USER && key < KEYC_USER + KEYC_NUSER) {
+ snprintf(out, sizeof out, "User%u", (u_int)(key - KEYC_USER));
+ return (out);
+ }
/*
* Special case: display C-@ as C-Space. Could do this below in
diff --git a/options-table.c b/options-table.c
index 6c0abbb5..91075871 100644
--- a/options-table.c
+++ b/options-table.c
@@ -136,6 +136,13 @@ const struct options_table_entry options_table[] = {
.separator = ","
},
+ { .name = "user-keys",
+ .type = OPTIONS_TABLE_ARRAY,
+ .scope = OPTIONS_TABLE_SERVER,
+ .default_str = "",
+ .separator = ","
+ },
+
{ .name = "assume-paste-time",
.type = OPTIONS_TABLE_NUMBER,
.scope = OPTIONS_TABLE_SESSION,
diff --git a/tmux.1 b/tmux.1
index 27833560..8cf1628c 100644
--- a/tmux.1
+++ b/tmux.1
@@ -2863,6 +2863,18 @@ removed from the session environment (as if
was given to the
.Ic set-environment
command).
+.It Ic user-keys[] Ar key
+Set list of user-defined key escape sequences.
+Each item is associated with a key named
+.Ql User0,
+.Ql User1,
+and so on.
+.Pp
+For example:
+.Bd -literal -offset indent
+set -s user-keys[0] '\e[5;30012~'
+bind User0 resize-pane -L 3
+.Ed
.It Xo Ic visual-activity
.Op Ic on | off
.Xc
diff --git a/tmux.h b/tmux.h
index e8f75aff..ef68c66b 100644
--- a/tmux.h
+++ b/tmux.h
@@ -87,6 +87,10 @@ struct tmuxproc;
#define KEYC_NONE 0xffff00000000ULL
#define KEYC_UNKNOWN 0xfffe00000000ULL
#define KEYC_BASE 0x000010000000ULL
+#define KEYC_USER 0x000020000000ULL
+
+/* Available user keys. */
+#define KEYC_NUSER 1000
/* Key modifier bits. */
#define KEYC_ESCAPE 0x200000000000ULL
diff --git a/tty-keys.c b/tty-keys.c
index 89745e0c..ca03628d 100644
--- a/tty-keys.c
+++ b/tty-keys.c
@@ -389,8 +389,9 @@ tty_keys_build(struct tty *tty)
{
const struct tty_default_key_raw *tdkr;
const struct tty_default_key_code *tdkc;
- u_int i;
- const char *s;
+ u_int i, size;
+ const char *s, *value;
+ struct options_entry *o;
if (tty->key_tree != NULL)
tty_keys_free(tty);
@@ -411,6 +412,15 @@ tty_keys_build(struct tty *tty)
tty_keys_add(tty, s, tdkc->key);
}
+
+ o = options_get(global_options, "user-keys");
+ if (o != NULL && options_array_size(o, &size) != -1) {
+ for (i = 0; i < size; i++) {
+ value = options_array_get(o, i);
+ if (value != NULL)
+ tty_keys_add(tty, value, KEYC_USER + i);
+ }
+ }
}
/* Free the entire key tree. */