summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-send-keys.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2019-07-09 14:03:12 +0000
committernicm <nicm@openbsd.org>2019-07-09 14:03:12 +0000
commita02c6cc0de6910021ed6426ac8e294cc43abf010 (patch)
tree5277a2ff17a84beab7008df3636e4574fcb04aef /usr.bin/tmux/cmd-send-keys.c
parentadd a test using fault injection to trigger OpenBSD::Temp errors (diff)
downloadwireguard-openbsd-a02c6cc0de6910021ed6426ac8e294cc43abf010.tar.xz
wireguard-openbsd-a02c6cc0de6910021ed6426ac8e294cc43abf010.zip
Add a -H flag to send-keys to send literal keys given as hex numbers
(needed for control clients to send mouse sequences). Also add some format flags for UTF-8 and SGR mouse mode. Requested by Bradley Smith in GitHub issues 1832 and 1833.
Diffstat (limited to 'usr.bin/tmux/cmd-send-keys.c')
-rw-r--r--usr.bin/tmux/cmd-send-keys.c79
1 files changed, 47 insertions, 32 deletions
diff --git a/usr.bin/tmux/cmd-send-keys.c b/usr.bin/tmux/cmd-send-keys.c
index 0aaaa5b2067..473fc616c8c 100644
--- a/usr.bin/tmux/cmd-send-keys.c
+++ b/usr.bin/tmux/cmd-send-keys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-send-keys.c,v 1.48 2019/05/12 08:58:09 nicm Exp $ */
+/* $OpenBSD: cmd-send-keys.c,v 1.49 2019/07/09 14:03:12 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -33,8 +33,8 @@ const struct cmd_entry cmd_send_keys_entry = {
.name = "send-keys",
.alias = "send",
- .args = { "lXRMN:t:", 0, -1 },
- .usage = "[-lXRM] [-N repeat-count] " CMD_TARGET_PANE_USAGE " key ...",
+ .args = { "HlXRMN:t:", 0, -1 },
+ .usage = "[-HlXRM] [-N repeat-count] " CMD_TARGET_PANE_USAGE " key ...",
.target = { 't', CMD_FIND_PANE, 0 },
@@ -56,9 +56,9 @@ const struct cmd_entry cmd_send_prefix_entry = {
};
static struct cmdq_item *
-cmd_send_keys_inject(struct client *c, struct cmd_find_state *fs,
- struct cmdq_item *item, key_code key)
+cmd_send_keys_inject_key(struct client *c, struct cmdq_item *item, key_code key)
{
+ struct cmd_find_state *fs = &item->target;
struct window_mode_entry *wme;
struct key_table *table;
struct key_binding *bd;
@@ -81,6 +81,44 @@ cmd_send_keys_inject(struct client *c, struct cmd_find_state *fs,
return (item);
}
+static struct cmdq_item *
+cmd_send_keys_inject_string(struct client *c, struct cmdq_item *item,
+ struct args *args, int i)
+{
+ const char *s = args->argv[i];
+ struct utf8_data *ud, *uc;
+ wchar_t wc;
+ key_code key;
+ char *endptr;
+ long n;
+ int literal;
+
+ if (args_has(args, 'H')) {
+ n = strtol(s, &endptr, 16);
+ if (*s =='\0' || n < 0 || n > 0xff || *endptr != '\0')
+ return (item);
+ return (cmd_send_keys_inject_key(c, item, KEYC_LITERAL|n));
+ }
+
+ literal = args_has(args, 'l');
+ if (!literal) {
+ key = key_string_lookup_string(s);
+ if (key != KEYC_NONE && key != KEYC_UNKNOWN)
+ return (cmd_send_keys_inject_key(c, item, key));
+ literal = 1;
+ }
+ if (literal) {
+ ud = utf8_fromcstr(s);
+ for (uc = ud; uc->size != 0; uc++) {
+ if (utf8_combine(uc, &wc) != UTF8_DONE)
+ continue;
+ item = cmd_send_keys_inject_key(c, item, wc);
+ }
+ free(ud);
+ }
+ return (item);
+}
+
static enum cmd_retval
cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
{
@@ -90,11 +128,8 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
struct mouse_event *m = &item->shared->mouse;
- struct cmd_find_state *fs = &item->target;
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
- struct utf8_data *ud, *uc;
- wchar_t wc;
- int i, literal;
+ int i;
key_code key;
u_int np = 1;
char *cause = NULL;
@@ -141,7 +176,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
key = options_get_number(s->options, "prefix2");
else
key = options_get_number(s->options, "prefix");
- cmd_send_keys_inject(c, fs, item, key);
+ cmd_send_keys_inject_key(c, item, key);
return (CMD_RETURN_NORMAL);
}
@@ -151,28 +186,8 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
}
for (; np != 0; np--) {
- for (i = 0; i < args->argc; i++) {
- literal = args_has(args, 'l');
- if (!literal) {
- key = key_string_lookup_string(args->argv[i]);
- if (key != KEYC_NONE && key != KEYC_UNKNOWN) {
- item = cmd_send_keys_inject(c, fs, item,
- key);
- } else
- literal = 1;
- }
- if (literal) {
- ud = utf8_fromcstr(args->argv[i]);
- for (uc = ud; uc->size != 0; uc++) {
- if (utf8_combine(uc, &wc) != UTF8_DONE)
- continue;
- item = cmd_send_keys_inject(c, fs, item,
- wc);
- }
- free(ud);
- }
- }
-
+ for (i = 0; i < args->argc; i++)
+ item = cmd_send_keys_inject_string(c, item, args, i);
}
return (CMD_RETURN_NORMAL);