mirror of
https://github.com/tmux/tmux.git
synced 2024-12-12 17:38:48 +00:00
Add user-keys option to allow user-defined keys to be set, from Dan
Aloni.
This commit is contained in:
parent
a67df17763
commit
95ed7d48c8
@ -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();
|
||||
|
10
key-string.c
10
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
|
||||
|
@ -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,
|
||||
|
12
tmux.1
12
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
|
||||
|
4
tmux.h
4
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
|
||||
|
14
tty-keys.c
14
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. */
|
||||
|
Loading…
Reference in New Issue
Block a user