1 /* $OpenBSD$ */
2
3 /*
4 * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <sys/types.h>
20
21 #include <stdlib.h>
22 #include <string.h>
23
24 #include "tmux.h"
25
26 /*
27 * Send keys to client.
28 */
29
30 enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmd_q *);
31
32 const struct cmd_entry cmd_send_keys_entry = {
33 .name = "send-keys",
34 .alias = "send",
35
36 .args = { "lRMt:", 0, -1 },
37 .usage = "[-lRM] " CMD_TARGET_PANE_USAGE " key ...",
38
39 .tflag = CMD_PANE,
40
41 .flags = 0,
42 .exec = cmd_send_keys_exec
43 };
44
45 const struct cmd_entry cmd_send_prefix_entry = {
46 .name = "send-prefix",
47 .alias = NULL,
48
49 .args = { "2t:", 0, 0 },
50 .usage = "[-2] " CMD_TARGET_PANE_USAGE,
51
52 .tflag = CMD_PANE,
53
54 .flags = 0,
55 .exec = cmd_send_keys_exec
56 };
57
58 enum cmd_retval
cmd_send_keys_exec(struct cmd * self,struct cmd_q * cmdq)59 cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq)
60 {
61 struct args *args = self->args;
62 struct window_pane *wp = cmdq->state.tflag.wp;
63 struct session *s = cmdq->state.tflag.s;
64 struct mouse_event *m = &cmdq->item->mouse;
65 const u_char *keystr;
66 int i, literal;
67 key_code key;
68
69 if (args_has(args, 'M')) {
70 wp = cmd_mouse_pane(m, &s, NULL);
71 if (wp == NULL) {
72 cmdq_error(cmdq, "no mouse target");
73 return (CMD_RETURN_ERROR);
74 }
75 window_pane_key(wp, NULL, s, m->key, m);
76 return (CMD_RETURN_NORMAL);
77 }
78
79 if (self->entry == &cmd_send_prefix_entry) {
80 if (args_has(args, '2'))
81 key = options_get_number(s->options, "prefix2");
82 else
83 key = options_get_number(s->options, "prefix");
84 window_pane_key(wp, NULL, s, key, NULL);
85 return (CMD_RETURN_NORMAL);
86 }
87
88 if (args_has(args, 'R'))
89 input_reset(wp, 1);
90
91 for (i = 0; i < args->argc; i++) {
92 literal = args_has(args, 'l');
93 if (!literal) {
94 key = key_string_lookup_string(args->argv[i]);
95 if (key != KEYC_NONE && key != KEYC_UNKNOWN)
96 window_pane_key(wp, NULL, s, key, NULL);
97 else
98 literal = 1;
99 }
100 if (literal) {
101 for (keystr = args->argv[i]; *keystr != '\0'; keystr++)
102 window_pane_key(wp, NULL, s, *keystr, NULL);
103 }
104 }
105
106 return (CMD_RETURN_NORMAL);
107 }
108