aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES6
-rw-r--r--GNUmakefile4
-rw-r--r--Makefile4
-rw-r--r--TODO8
-rw-r--r--cmd-send-keys.c143
-rw-r--r--cmd.c3
-rw-r--r--tmux.114
-rw-r--r--tmux.h3
8 files changed, 171 insertions, 14 deletions
diff --git a/CHANGES b/CHANGES
index 6ab95bed..297f834b 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+01 June 2008
+
+* New command, send-keys, will send a set of keys to a window.
+
31 May 2008
* Fix so tmux doesn't hang if the initial window fails for some reason. This
@@ -310,4 +314,4 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.94 2008-05-31 20:04:15 nicm Exp $
+$Id: CHANGES,v 1.95 2008-06-01 20:20:25 nicm Exp $
diff --git a/GNUmakefile b/GNUmakefile
index 82254a7a..e9cf5da3 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -1,4 +1,4 @@
-# $Id: GNUmakefile,v 1.11 2008-02-10 19:46:17 nicm Exp $
+# $Id: GNUmakefile,v 1.12 2008-06-01 20:20:25 nicm Exp $
.PHONY: clean
@@ -20,7 +20,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-set-option.c cmd-rename-window.c cmd-select-window.c \
cmd-list-windows.c cmd-attach-session.c cmd-send-prefix.c \
cmd-refresh-client.c cmd-kill-window.c cmd-list-clients.c \
- cmd-link-window.c cmd-unlink-window.c cmd-next-window.c \
+ cmd-link-window.c cmd-unlink-window.c cmd-next-window.c cmd-send-keys.c \
cmd-swap-window.c cmd-rename-session.c cmd-kill-session.c \
cmd-switch-client.c cmd-has-session.c cmd-scroll-mode.c cmd-copy-mode.c \
cmd-paste-buffer.c window-scroll.c window-more.c window-copy.c \
diff --git a/Makefile b/Makefile
index cf31418e..3301b558 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.52 2007-12-06 09:46:21 nicm Exp $
+# $Id: Makefile,v 1.53 2008-06-01 20:20:25 nicm Exp $
.SUFFIXES: .c .o .y .h
.PHONY: clean update-index.html upload-index.html
@@ -24,7 +24,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-set-option.c cmd-rename-window.c cmd-select-window.c \
cmd-list-windows.c cmd-attach-session.c cmd-send-prefix.c \
cmd-refresh-client.c cmd-kill-window.c cmd-list-clients.c \
- cmd-link-window.c cmd-unlink-window.c cmd-next-window.c \
+ cmd-link-window.c cmd-unlink-window.c cmd-next-window.c cmd-send-keys.c \
cmd-swap-window.c cmd-rename-session.c cmd-kill-session.c \
cmd-switch-client.c cmd-has-session.c cmd-scroll-mode.c cmd-copy-mode.c \
cmd-paste-buffer.c window-scroll.c window-more.c window-copy.c \
diff --git a/TODO b/TODO
index 920986de..bef16669 100644
--- a/TODO
+++ b/TODO
@@ -34,15 +34,12 @@
kill server
show-options command
command to run something without a window at all?
- command to insert a key into a window (send-key)
- should paste-buffer become send-buffer.....
- command to insert any data (a string) into a window (paste-data?)
command to purge window history
extend list-clients to list clients attached to a session (-a for all?)
bring back detach-session to detach all clients on a session?
paste buffer etc shouldn't be limited to keys
buffer manip: clear, view etc (clear-buffer, show-buffer)
-- function groups, bind-key ^W { select-window 0; send-key ^W } etc
+- function groups, bind-key ^W { select-window 0; send-key ^W } etc ***
- allow fnmatch for -c, so that you can, eg, detach all clients
- session specification is all over the place. some things use -s before cmd,
some -s after, some no -s, there are various uses of -n. the differences are
@@ -51,7 +48,7 @@
- bind non prefix keys
- stuff like rename would be nice to be able to do in-client like screen, if
it could be implemented in a non-icky way
-- there is to much redrawing. use flags?
+- there is too much redrawing. use flags?
- command mode (! + type tmux command)
- garbage collect window history (100 lines at a time?) if it hasn't been used
in $x time (need window creation/use times)
@@ -78,4 +75,3 @@
- anything which uses cmd_{send,recv}_string will break if the string is
split. string length should be part of the command size
- chmod +x socket when any client is attached (upd in lost/accept)
-
diff --git a/cmd-send-keys.c b/cmd-send-keys.c
new file mode 100644
index 00000000..25ee1c48
--- /dev/null
+++ b/cmd-send-keys.c
@@ -0,0 +1,143 @@
+/* $Id: cmd-send-keys.c,v 1.1 2008-06-01 20:20:25 nicm Exp $ */
+
+/*
+ * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <getopt.h>
+#include <stdlib.h>
+
+#include "tmux.h"
+
+/*
+ * Change session name.
+ */
+
+int cmd_send_keys_parse(void **, int, char **, char **);
+void cmd_send_keys_exec(void *, struct cmd_ctx *);
+void cmd_send_keys_send(void *, struct buffer *);
+void cmd_send_keys_recv(void **, struct buffer *);
+void cmd_send_keys_free(void *);
+
+struct cmd_send_keys_data {
+ u_int nkeys;
+ int *keys;
+};
+
+const struct cmd_entry cmd_send_keys_entry = {
+ "send-keys", "send", "key ...",
+ 0,
+ cmd_send_keys_parse,
+ cmd_send_keys_exec,
+ cmd_send_keys_send,
+ cmd_send_keys_recv,
+ cmd_send_keys_free
+};
+
+int
+cmd_send_keys_parse(void **ptr, int argc, char **argv, char **cause)
+{
+ struct cmd_send_keys_data *data;
+ int opt, key;
+ char *s;
+
+ *ptr = data = xmalloc(sizeof *data);
+ data->nkeys = 0;
+ data->keys = NULL;
+
+ while ((opt = getopt(argc, argv, "")) != EOF) {
+ switch (opt) {
+ default:
+ goto usage;
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ if (argc == 0)
+ goto usage;
+
+ while (argc-- != 0) {
+ if ((key = key_string_lookup_string(*argv)) != KEYC_NONE) {
+ data->keys = xrealloc(
+ data->keys, data->nkeys + 1, sizeof *data->keys);
+ data->keys[data->nkeys++] = key;
+ } else {
+ for (s = *argv; *s != '\0'; s++) {
+ data->keys = xrealloc(data->keys,
+ data->nkeys + 1, sizeof *data->keys);
+ data->keys[data->nkeys++] = *s;
+ }
+ }
+
+ argv++;
+ }
+
+ return (0);
+
+usage:
+ usage(cause, "%s %s",
+ cmd_send_keys_entry.name, cmd_send_keys_entry.usage);
+
+ cmd_send_keys_free(data);
+ return (-1);
+}
+
+void
+cmd_send_keys_exec(void *ptr, struct cmd_ctx *ctx)
+{
+ struct cmd_send_keys_data *data = ptr;
+ u_int i;
+
+ if (data == NULL)
+ return;
+
+ for (i = 0; i < data->nkeys; i++)
+ window_key(ctx->client->session->curw->window, data->keys[i]);
+
+ if (ctx->cmdclient != NULL)
+ server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+}
+
+void
+cmd_send_keys_send(void *ptr, struct buffer *b)
+{
+ struct cmd_send_keys_data *data = ptr;
+
+ buffer_write(b, data, sizeof *data);
+ buffer_write(b, data->keys, data->nkeys * sizeof *data->keys);
+}
+
+void
+cmd_send_keys_recv(void **ptr, struct buffer *b)
+{
+ struct cmd_send_keys_data *data;
+
+ *ptr = data = xmalloc(sizeof *data);
+ buffer_read(b, data, sizeof *data);
+ data->keys = xcalloc(data->nkeys, sizeof *data->keys);
+ buffer_read(b, data->keys, data->nkeys * sizeof *data->keys);
+}
+
+void
+cmd_send_keys_free(void *ptr)
+{
+ struct cmd_send_keys_data *data = ptr;
+
+ if (data->keys != NULL)
+ xfree(data->keys);
+ xfree(data);
+}
diff --git a/cmd.c b/cmd.c
index 8e46a92f..52a2cf83 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,4 +1,4 @@
-/* $Id: cmd.c,v 1.33 2007-12-06 09:46:22 nicm Exp $ */
+/* $Id: cmd.c,v 1.34 2008-06-01 20:20:25 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -47,6 +47,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_rename_window_entry,
&cmd_scroll_mode_entry,
&cmd_select_window_entry,
+ &cmd_send_keys_entry,
&cmd_send_prefix_entry,
&cmd_set_option_entry,
&cmd_swap_window_entry,
diff --git a/tmux.1 b/tmux.1
index 48a9618b..0e4714b7 100644
--- a/tmux.1
+++ b/tmux.1
@@ -1,4 +1,4 @@
-.\" $Id: tmux.1,v 1.23 2008-05-31 23:08:48 nicm Exp $
+.\" $Id: tmux.1,v 1.24 2008-06-01 20:20:25 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -421,6 +421,18 @@ This command works only if bound to a key.
.D1 (alias: Ic selectw )
Select the window at
.Ar index .
+.It Xo Ic send-keys Ar key Ar ...
+.Xc
+Send a key or keys to a window.
+Each argument
+.Ar key
+is the name of the key (such as
+.Ql ^A
+or
+.Ql npage
+) to send; if the string is not recognised as a key, it is sent as a series of
+characters.
+All the arguments are sent sequentially from first to last.
.It Xo Ic send-prefix
.Xc
Send the prefix key to a window as if it was pressed.
diff --git a/tmux.h b/tmux.h
index 3a3cede0..ff5dbb41 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.115 2008-05-31 18:04:57 nicm Exp $ */
+/* $Id: tmux.h,v 1.116 2008-06-01 20:20:25 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -748,6 +748,7 @@ extern const struct cmd_entry cmd_rename_session_entry;
extern const struct cmd_entry cmd_rename_window_entry;
extern const struct cmd_entry cmd_scroll_mode_entry;
extern const struct cmd_entry cmd_select_window_entry;
+extern const struct cmd_entry cmd_send_keys_entry;
extern const struct cmd_entry cmd_send_prefix_entry;
extern const struct cmd_entry cmd_set_option_entry;
extern const struct cmd_entry cmd_swap_window_entry;