Annotation of src/usr.bin/tmux/cmd-send-keys.c, Revision 1.35
1.35 ! nicm 1: /* $OpenBSD: cmd-send-keys.c,v 1.34 2016/11/29 12:54:46 nicm Exp $ */
1.1 nicm 2:
3: /*
1.28 nicm 4: * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1 nicm 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>
1.10 nicm 22: #include <string.h>
1.1 nicm 23:
24: #include "tmux.h"
25:
26: /*
27: * Send keys to client.
28: */
29:
1.33 nicm 30: static enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmdq_item *);
1.1 nicm 31:
32: const struct cmd_entry cmd_send_keys_entry = {
1.25 nicm 33: .name = "send-keys",
34: .alias = "send",
35:
1.30 nicm 36: .args = { "lXRMN:t:", 0, -1 },
37: .usage = "[-lXRM] [-N repeat-count] " CMD_TARGET_PANE_USAGE " key ...",
1.25 nicm 38:
1.26 nicm 39: .tflag = CMD_PANE,
40:
1.31 nicm 41: .flags = CMD_AFTERHOOK,
1.25 nicm 42: .exec = cmd_send_keys_exec
1.1 nicm 43: };
44:
1.14 nicm 45: const struct cmd_entry cmd_send_prefix_entry = {
1.25 nicm 46: .name = "send-prefix",
47: .alias = NULL,
48:
49: .args = { "2t:", 0, 0 },
50: .usage = "[-2] " CMD_TARGET_PANE_USAGE,
51:
1.26 nicm 52: .tflag = CMD_PANE,
53:
1.31 nicm 54: .flags = CMD_AFTERHOOK,
1.25 nicm 55: .exec = cmd_send_keys_exec
1.14 nicm 56: };
57:
1.29 nicm 58: static enum cmd_retval
1.33 nicm 59: cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
1.1 nicm 60: {
1.9 nicm 61: struct args *args = self->args;
1.33 nicm 62: struct client *c = item->state.c;
63: struct window_pane *wp = item->state.tflag.wp;
64: struct session *s = item->state.tflag.s;
65: struct mouse_event *m = &item->mouse;
1.35 ! nicm 66: struct utf8_data *ud, *uc;
! 67: wchar_t wc;
1.23 nicm 68: int i, literal;
1.22 nicm 69: key_code key;
1.34 nicm 70: u_int np = 1;
1.30 nicm 71: char *cause = NULL;
72:
73: if (args_has(args, 'N')) {
74: np = args_strtonum(args, 'N', 1, UINT_MAX, &cause);
75: if (cause != NULL) {
1.34 nicm 76: cmdq_error(item, "repeat count %s", cause);
1.30 nicm 77: free(cause);
78: return (CMD_RETURN_ERROR);
79: }
80: }
81:
82: if (args_has(args, 'X')) {
83: if (wp->mode == NULL || wp->mode->command == NULL) {
1.33 nicm 84: cmdq_error(item, "not in a mode");
1.30 nicm 85: return (CMD_RETURN_ERROR);
86: }
1.34 nicm 87: wp->modeprefix = np;
1.30 nicm 88: if (!m->valid)
89: wp->mode->command(wp, c, s, args, NULL);
90: else
91: wp->mode->command(wp, c, s, args, m);
92: return (CMD_RETURN_NORMAL);
93: }
94:
1.19 nicm 95: if (args_has(args, 'M')) {
96: wp = cmd_mouse_pane(m, &s, NULL);
97: if (wp == NULL) {
1.33 nicm 98: cmdq_error(item, "no mouse target");
1.19 nicm 99: return (CMD_RETURN_ERROR);
100: }
101: window_pane_key(wp, NULL, s, m->key, m);
102: return (CMD_RETURN_NORMAL);
103: }
1.14 nicm 104:
105: if (self->entry == &cmd_send_prefix_entry) {
106: if (args_has(args, '2'))
1.21 nicm 107: key = options_get_number(s->options, "prefix2");
1.14 nicm 108: else
1.21 nicm 109: key = options_get_number(s->options, "prefix");
1.19 nicm 110: window_pane_key(wp, NULL, s, key, NULL);
1.14 nicm 111: return (CMD_RETURN_NORMAL);
112: }
1.10 nicm 113:
1.20 nicm 114: if (args_has(args, 'R'))
1.27 nicm 115: input_reset(wp, 1);
1.1 nicm 116:
1.34 nicm 117: for (; np != 0; np--) {
118: for (i = 0; i < args->argc; i++) {
119: literal = args_has(args, 'l');
120: if (!literal) {
121: key = key_string_lookup_string(args->argv[i]);
122: if (key != KEYC_NONE && key != KEYC_UNKNOWN)
123: window_pane_key(wp, NULL, s, key, NULL);
124: else
125: literal = 1;
126: }
127: if (literal) {
1.35 ! nicm 128: ud = utf8_fromcstr(args->argv[i]);
! 129: for (uc = ud; uc->size != 0; uc++) {
! 130: if (utf8_combine(uc, &wc) == UTF8_DONE)
! 131: window_pane_key(wp, NULL, s, wc, NULL);
! 132: }
! 133: free(ud);
1.34 nicm 134: }
1.9 nicm 135: }
1.34 nicm 136:
1.9 nicm 137: }
1.1 nicm 138:
1.12 nicm 139: return (CMD_RETURN_NORMAL);
1.1 nicm 140: }