diff --git a/CHANGES b/CHANGES index bb44bd63..ae1b9a30 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ 16 November 2007 +* (nicm) Accept "-c client-tty" on command line to allow client manipulation + commands, and change detach-/refresh-session to detach-/refresh-client (this + loses the -a behaviour, but at some point -session versions may return, and + -c will allow fnmatch(3)). * (nicm) List available commands on ambiguous command. 12 November 2007 @@ -210,4 +214,4 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.68 2007-11-16 13:23:59 nicm Exp $ +$Id: CHANGES,v 1.69 2007-11-16 21:12:31 nicm Exp $ diff --git a/GNUmakefile b/GNUmakefile index 346417e0..186eef67 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,4 +1,4 @@ -# $Id: GNUmakefile,v 1.3 2007-11-09 15:23:28 nicm Exp $ +# $Id: GNUmakefile,v 1.4 2007-11-16 21:12:31 nicm Exp $ .PHONY: clean @@ -14,12 +14,12 @@ META?= \002 SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ xmalloc.c xmalloc-debug.c input.c input-keys.c screen.c window.c \ session.c local.c log.c client.c client-msg.c client-fn.c key-string.c \ - key-bindings.c resize.c cmd.c cmd-new-session.c cmd-detach-session.c \ + key-bindings.c resize.c cmd.c cmd-new-session.c cmd-detach-client.c \ cmd-list-sessions.c cmd-new-window.c cmd-next-window.c cmd-bind-key.c \ cmd-unbind-key.c cmd-previous-window.c cmd-last-window.c cmd-list-keys.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-session.c cmd-kill-window.c cmd-list-clients.c \ + cmd-refresh-client.c cmd-kill-window.c cmd-list-clients.c \ cmd-has-session.c cmd-link-window.c cmd-unlink-window.c \ cmd-swap-window.c cmd-rename-session.c diff --git a/Makefile b/Makefile index 43884440..5ca34443 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.39 2007-11-12 14:21:40 nicm Exp $ +# $Id: Makefile,v 1.40 2007-11-16 21:12:31 nicm Exp $ .SUFFIXES: .c .o .y .h .PHONY: clean @@ -18,12 +18,12 @@ META?= \002 # C-b SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ xmalloc.c xmalloc-debug.c input.c input-keys.c screen.c window.c \ session.c local.c log.c client.c client-msg.c client-fn.c key-string.c \ - key-bindings.c resize.c cmd.c cmd-new-session.c cmd-detach-session.c \ + key-bindings.c resize.c cmd.c cmd-new-session.c cmd-detach-client.c \ cmd-list-sessions.c cmd-new-window.c cmd-next-window.c cmd-bind-key.c \ cmd-unbind-key.c cmd-previous-window.c cmd-last-window.c cmd-list-keys.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-session.c cmd-kill-window.c cmd-list-clients.c \ + cmd-refresh-client.c cmd-kill-window.c cmd-list-clients.c \ cmd-has-session.c cmd-link-window.c cmd-unlink-window.c \ cmd-swap-window.c cmd-rename-session.c cmd-kill-session.c diff --git a/TODO b/TODO index 91ea9013..49b0441b 100644 --- a/TODO +++ b/TODO @@ -53,16 +53,19 @@ - per-session toolbar state, other options - force-default option: assume terminal supports default colours even if AX is missing (like, eg, xterm-color in an aterm) -- refer to windows by name etc (duplicates?) +- refer to windows by name etc (duplicates? fnmatch?) - commands: kill server command to run something without a window at all? command to insert a key into a window (send-key) + extend list-clients to list clients attached to a session (-a for all?) + bring back detach-session to detach all clients on a session? - function groups, bind-key ^W { select-window 0; send-key ^W } etc - more(1) style handling for in-client output +- allow fnmatch for -c, so that you can, eg, detach all clients -- For 0.1 -------------------------------------------------------------------- -- fix mutt problems with redraw (mutt's) status line when reading mail +- -- For 0.2 -------------------------------------------------------------------- - copy and paste diff --git a/cmd-attach-session.c b/cmd-attach-session.c index 5f6aafc7..621c2bfd 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -1,4 +1,4 @@ -/* $Id: cmd-attach-session.c,v 1.8 2007-11-13 09:53:46 nicm Exp $ */ +/* $Id: cmd-attach-session.c,v 1.9 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -38,7 +38,7 @@ struct cmd_attach_session_data { const struct cmd_entry cmd_attach_session_entry = { "attach-session", "attach", "[-d]", - CMD_CANTNEST, + CMD_CANTNEST|CMD_NOCLIENT, cmd_attach_session_parse, cmd_attach_session_exec, cmd_attach_session_send, @@ -87,18 +87,18 @@ cmd_attach_session_exec(void *ptr, struct cmd_ctx *ctx) if (ctx->flags & CMD_KEY) return; - if (!(ctx->client->flags & CLIENT_TERMINAL)) { + if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) { ctx->error(ctx, "not a terminal"); return; } if (data->flag_detach) server_write_session(ctx->session, MSG_DETACH, NULL, 0); - ctx->client->session = ctx->session; + ctx->cmdclient->session = ctx->session; - server_write_client(ctx->client, MSG_READY, NULL, 0); + server_write_client(ctx->cmdclient, MSG_READY, NULL, 0); recalculate_sizes(); - server_redraw_client(ctx->client); + server_redraw_client(ctx->cmdclient); } void diff --git a/cmd-bind-key.c b/cmd-bind-key.c index fff9a766..5f739aca 100644 --- a/cmd-bind-key.c +++ b/cmd-bind-key.c @@ -1,4 +1,4 @@ -/* $Id: cmd-bind-key.c,v 1.6 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-bind-key.c,v 1.7 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -39,7 +39,7 @@ struct cmd_bind_key_data { const struct cmd_entry cmd_bind_key_entry = { "bind-key", "bind", "key command [arguments]", - CMD_NOSESSION, + CMD_NOCLIENT|CMD_NOSESSION, cmd_bind_key_parse, cmd_bind_key_exec, cmd_bind_key_send, @@ -99,8 +99,8 @@ cmd_bind_key_exec(void *ptr, unused struct cmd_ctx *ctx) key_bindings_add(data->key, data->cmd); data->cmd = NULL; /* avoid free */ - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } void diff --git a/cmd-detach-client.c b/cmd-detach-client.c new file mode 100644 index 00000000..64a31b85 --- /dev/null +++ b/cmd-detach-client.c @@ -0,0 +1,48 @@ +/* $Id: cmd-detach-client.c,v 1.1 2007-11-16 21:12:31 nicm Exp $ */ + +/* + * Copyright (c) 2007 Nicholas Marriott + * + * 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 + +#include + +#include "tmux.h" + +/* + * Detach a client. + */ + +void cmd_detach_client_exec(void *, struct cmd_ctx *); + +const struct cmd_entry cmd_detach_client_entry = { + "detach-client", "detach", "", + CMD_NOSESSION, + NULL, + cmd_detach_client_exec, + NULL, + NULL, + NULL +}; + +void +cmd_detach_client_exec(unused void *ptr, struct cmd_ctx *ctx) +{ + server_write_client(ctx->client, MSG_DETACH, NULL, 0); + + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); +} diff --git a/cmd-detach-session.c b/cmd-detach-session.c deleted file mode 100644 index 6c8be72c..00000000 --- a/cmd-detach-session.c +++ /dev/null @@ -1,130 +0,0 @@ -/* $Id: cmd-detach-session.c,v 1.7 2007-11-13 09:53:47 nicm Exp $ */ - -/* - * Copyright (c) 2007 Nicholas Marriott - * - * 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 - -#include - -#include "tmux.h" - -/* - * Detach session. If called with -a detach all clients attached to specified - * session, otherwise detach current session on key press only. - */ - -int cmd_detach_session_parse(void **, int, char **, char **); -void cmd_detach_session_exec(void *, struct cmd_ctx *); -void cmd_detach_session_send(void *, struct buffer *); -void cmd_detach_session_recv(void **, struct buffer *); -void cmd_detach_session_free(void *); - -struct cmd_detach_session_data { - int flag_all; -}; - -const struct cmd_entry cmd_detach_session_entry = { - "detach-session", "detach", "[-a]", - 0, - cmd_detach_session_parse, - cmd_detach_session_exec, - cmd_detach_session_send, - cmd_detach_session_recv, - cmd_detach_session_free -}; - -int -cmd_detach_session_parse(void **ptr, int argc, char **argv, char **cause) -{ - struct cmd_detach_session_data *data; - int opt; - - *ptr = data = xmalloc(sizeof *data); - data->flag_all = 0; - - while ((opt = getopt(argc, argv, "a")) != EOF) { - switch (opt) { - case 'a': - data->flag_all = 1; - break; - default: - goto usage; - } - } - argc -= optind; - argv += optind; - if (argc != 0) - goto usage; - - return (0); - -usage: - usage(cause, "%s %s", - cmd_detach_session_entry.name, cmd_detach_session_entry.usage); - - cmd_detach_session_free(data); - return (-1); -} - -void -cmd_detach_session_exec(void *ptr, struct cmd_ctx *ctx) -{ - struct cmd_detach_session_data *data = ptr, std = { 0 }; - struct client *c; - u_int i; - - if (data == NULL) - data = &std; - - if (data->flag_all) { - for (i = 0; i < ARRAY_LENGTH(&clients); i++) { - c = ARRAY_ITEM(&clients, i); - if (c == NULL || c->session != ctx->session) - continue; - server_write_client(c, MSG_DETACH, NULL, 0); - } - } else if (ctx->flags & CMD_KEY) - server_write_client(ctx->client, MSG_DETACH, NULL, 0); - - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); -} - -void -cmd_detach_session_send(void *ptr, struct buffer *b) -{ - struct cmd_detach_session_data *data = ptr; - - buffer_write(b, data, sizeof *data); -} - -void -cmd_detach_session_recv(void **ptr, struct buffer *b) -{ - struct cmd_detach_session_data *data; - - *ptr = data = xmalloc(sizeof *data); - buffer_read(b, data, sizeof *data); -} - -void -cmd_detach_session_free(void *ptr) -{ - struct cmd_detach_session_data *data = ptr; - - xfree(data); -} diff --git a/cmd-has-session.c b/cmd-has-session.c index 692e460a..b6d3fdf5 100644 --- a/cmd-has-session.c +++ b/cmd-has-session.c @@ -1,4 +1,4 @@ -/* $Id: cmd-has-session.c,v 1.2 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-has-session.c,v 1.3 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -33,7 +33,7 @@ void cmd_has_session_exec(void *, struct cmd_ctx *); const struct cmd_entry cmd_has_session_entry = { "has-session", "has", "", - 0, + CMD_NOCLIENT, NULL, cmd_has_session_exec, NULL, @@ -44,6 +44,6 @@ const struct cmd_entry cmd_has_session_entry = { void cmd_has_session_exec(unused void *ptr, struct cmd_ctx *ctx) { - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } diff --git a/cmd-kill-session.c b/cmd-kill-session.c index 40d2e902..b7853810 100644 --- a/cmd-kill-session.c +++ b/cmd-kill-session.c @@ -1,4 +1,4 @@ -/* $Id: cmd-kill-session.c,v 1.2 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-kill-session.c,v 1.3 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -34,7 +34,7 @@ void cmd_kill_session_exec(void *, struct cmd_ctx *); const struct cmd_entry cmd_kill_session_entry = { "kill-session", NULL, "", - 0, + CMD_NOCLIENT, NULL, cmd_kill_session_exec, NULL, @@ -59,5 +59,5 @@ cmd_kill_session_exec(unused void *ptr, struct cmd_ctx *ctx) session_destroy(ctx->session); if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } diff --git a/cmd-kill-window.c b/cmd-kill-window.c index 20272526..e962fc75 100644 --- a/cmd-kill-window.c +++ b/cmd-kill-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-kill-window.c,v 1.5 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-kill-window.c,v 1.6 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -39,7 +39,7 @@ struct cmd_kill_window_data { const struct cmd_entry cmd_kill_window_entry = { "kill-window", "killw", "[-i index]", - 0, + CMD_NOCLIENT, cmd_kill_window_parse, cmd_kill_window_exec, cmd_kill_window_send, @@ -118,8 +118,8 @@ cmd_kill_window_exec(void *ptr, struct cmd_ctx *ctx) server_redraw_client(c); } - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } void diff --git a/cmd-last-window.c b/cmd-last-window.c index dd3ff6d1..7052c1f1 100644 --- a/cmd-last-window.c +++ b/cmd-last-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-last-window.c,v 1.4 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-last-window.c,v 1.5 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -31,7 +31,7 @@ void cmd_last_window_exec(void *, struct cmd_ctx *); const struct cmd_entry cmd_last_window_entry = { "last-window", "last", "", - 0, + CMD_NOCLIENT, NULL, cmd_last_window_exec, NULL, @@ -47,6 +47,6 @@ cmd_last_window_exec(unused void *ptr, struct cmd_ctx *ctx) else ctx->error(ctx, "no last window"); - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } diff --git a/cmd-link-window.c b/cmd-link-window.c index 093c4568..918b0492 100644 --- a/cmd-link-window.c +++ b/cmd-link-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-link-window.c,v 1.5 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-link-window.c,v 1.6 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -42,7 +42,7 @@ struct cmd_link_window_data { const struct cmd_entry cmd_link_window_entry = { "link-window", "linkw", "[-i index] name index", - 0, + CMD_NOCLIENT, cmd_link_window_parse, cmd_link_window_exec, cmd_link_window_send, @@ -142,8 +142,8 @@ cmd_link_window_exec(void *ptr, struct cmd_ctx *ctx) } else server_status_session(dst); - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } void diff --git a/cmd-list-clients.c b/cmd-list-clients.c index 2ca94896..0713e258 100644 --- a/cmd-list-clients.c +++ b/cmd-list-clients.c @@ -1,4 +1,4 @@ -/* $Id: cmd-list-clients.c,v 1.1 2007-10-23 09:36:19 nicm Exp $ */ +/* $Id: cmd-list-clients.c,v 1.2 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -32,7 +32,7 @@ void cmd_list_clients_exec(void *, struct cmd_ctx *); const struct cmd_entry cmd_list_clients_entry = { "list-clients", "lsc", "", - CMD_NOSESSION, + CMD_NOCLIENT|CMD_NOSESSION, NULL, cmd_list_clients_exec, NULL, @@ -55,6 +55,6 @@ cmd_list_clients_exec(unused void *ptr, struct cmd_ctx *ctx) "%s: %s [%ux%u]", c->tty, c->session->name, c->sx, c->sy); } - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } diff --git a/cmd-list-keys.c b/cmd-list-keys.c index c4cc6180..f4bb6bf1 100644 --- a/cmd-list-keys.c +++ b/cmd-list-keys.c @@ -1,4 +1,4 @@ -/* $Id: cmd-list-keys.c,v 1.4 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-list-keys.c,v 1.5 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -31,7 +31,7 @@ void cmd_list_keys_exec(void *, struct cmd_ctx *); const struct cmd_entry cmd_list_keys_entry = { "list-keys", "lsk", "", - CMD_NOSESSION, + CMD_NOCLIENT|CMD_NOSESSION, NULL, cmd_list_keys_exec, NULL, @@ -53,6 +53,6 @@ cmd_list_keys_exec(unused void *ptr, struct cmd_ctx *ctx) ctx->print(ctx, "%11s: %s", key, bd->cmd->entry->name); } - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } diff --git a/cmd-list-sessions.c b/cmd-list-sessions.c index 4fc102cf..8b9fd201 100644 --- a/cmd-list-sessions.c +++ b/cmd-list-sessions.c @@ -1,4 +1,4 @@ -/* $Id: cmd-list-sessions.c,v 1.8 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-list-sessions.c,v 1.9 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -32,7 +32,7 @@ void cmd_list_sessions_exec(void *, struct cmd_ctx *); const struct cmd_entry cmd_list_sessions_entry = { "list-sessions", "ls", "", - CMD_NOSESSION, + CMD_NOCLIENT|CMD_NOSESSION, NULL, cmd_list_sessions_exec, NULL, @@ -63,6 +63,6 @@ cmd_list_sessions_exec(unused void *ptr, struct cmd_ctx *ctx) " (created %s) [%ux%u]", s->name, n, tim, s->sx, s->sy); } - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } diff --git a/cmd-list-windows.c b/cmd-list-windows.c index ab80d3b3..1340a7ae 100644 --- a/cmd-list-windows.c +++ b/cmd-list-windows.c @@ -1,4 +1,4 @@ -/* $Id: cmd-list-windows.c,v 1.7 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-list-windows.c,v 1.8 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -31,7 +31,7 @@ void cmd_list_windows_exec(void *, struct cmd_ctx *); const struct cmd_entry cmd_list_windows_entry = { "list-windows", "lsw", NULL, - 0, + CMD_NOCLIENT, NULL, cmd_list_windows_exec, NULL, @@ -52,6 +52,6 @@ cmd_list_windows_exec(unused void *ptr, struct cmd_ctx *ctx) w->screen.sx, w->screen.sy); } - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } diff --git a/cmd-new-session.c b/cmd-new-session.c index 4122e539..75574f41 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $Id: cmd-new-session.c,v 1.16 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-new-session.c,v 1.17 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -42,7 +42,7 @@ struct cmd_new_session_data { const struct cmd_entry cmd_new_session_entry = { "new-session", "new", "[-d] [-s session-name] [-n window-name] [command]", - CMD_STARTSERVER|CMD_NOSESSION|CMD_CANTNEST, + CMD_STARTSERVER|CMD_NOCLIENT|CMD_NOSESSION|CMD_CANTNEST, cmd_new_session_parse, cmd_new_session_exec, cmd_new_session_send, @@ -110,7 +110,7 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx) if (ctx->flags & CMD_KEY) return; - c = ctx->client; + c = ctx->cmdclient; if (!data->flag_detached && !(c->flags & CLIENT_TERMINAL)) { ctx->error(ctx, "not a terminal"); return; diff --git a/cmd-new-window.c b/cmd-new-window.c index ebb434c9..730c0293 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-new-window.c,v 1.12 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-new-window.c,v 1.13 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -42,7 +42,7 @@ struct cmd_new_window_data { const struct cmd_entry cmd_new_window_entry = { "new-window", "neww", "[-d] [-i index] [-n name] [command]", - 0, + CMD_NOCLIENT, cmd_new_window_parse, cmd_new_window_exec, cmd_new_window_send, @@ -129,8 +129,8 @@ cmd_new_window_exec(void *ptr, struct cmd_ctx *ctx) } else server_status_session(ctx->session); - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } void diff --git a/cmd-next-window.c b/cmd-next-window.c index 773f2b36..8a807714 100644 --- a/cmd-next-window.c +++ b/cmd-next-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-next-window.c,v 1.4 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-next-window.c,v 1.5 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -31,7 +31,7 @@ void cmd_next_window_exec(void *, struct cmd_ctx *); const struct cmd_entry cmd_next_window_entry = { "next-window", "next", "", - 0, + CMD_NOCLIENT, NULL, cmd_next_window_exec, NULL, @@ -47,6 +47,6 @@ cmd_next_window_exec(unused void *ptr, struct cmd_ctx *ctx) else ctx->error(ctx, "no next window"); - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } diff --git a/cmd-previous-window.c b/cmd-previous-window.c index 640cddf7..cdf0b7d8 100644 --- a/cmd-previous-window.c +++ b/cmd-previous-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-previous-window.c,v 1.4 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-previous-window.c,v 1.5 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -31,7 +31,7 @@ void cmd_previous_window_exec(void *, struct cmd_ctx *); const struct cmd_entry cmd_previous_window_entry = { "previous-window", "prev", "", - 0, + CMD_NOCLIENT, NULL, cmd_previous_window_exec, NULL, @@ -47,6 +47,6 @@ cmd_previous_window_exec(unused void *ptr, struct cmd_ctx *ctx) else ctx->error(ctx, "no previous window"); - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } diff --git a/cmd-refresh-client.c b/cmd-refresh-client.c new file mode 100644 index 00000000..ba2ce5bf --- /dev/null +++ b/cmd-refresh-client.c @@ -0,0 +1,48 @@ +/* $Id: cmd-refresh-client.c,v 1.1 2007-11-16 21:12:31 nicm Exp $ */ + +/* + * Copyright (c) 2007 Nicholas Marriott + * + * 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 + +#include + +#include "tmux.h" + +/* + * Refresh client. + */ + +void cmd_refresh_client_exec(void *, struct cmd_ctx *); + +const struct cmd_entry cmd_refresh_client_entry = { + "refresh-client", "refresh", "", + 0, + NULL, + cmd_refresh_client_exec, + NULL, + NULL, + NULL +}; + +void +cmd_refresh_client_exec(unused void *ptr, struct cmd_ctx *ctx) +{ + server_redraw_client(ctx->client); + + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); +} diff --git a/cmd-refresh-session.c b/cmd-refresh-session.c deleted file mode 100644 index 5853ee54..00000000 --- a/cmd-refresh-session.c +++ /dev/null @@ -1,130 +0,0 @@ -/* $Id: cmd-refresh-session.c,v 1.2 2007-11-13 09:53:47 nicm Exp $ */ - -/* - * Copyright (c) 2007 Nicholas Marriott - * - * 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 - -#include - -#include "tmux.h" - -/* - * Refresh session. If called with -a refresh all clients attached to specified - * session, otherwise refresh current session on key press only. - */ - -int cmd_refresh_session_parse(void **, int, char **, char **); -void cmd_refresh_session_exec(void *, struct cmd_ctx *); -void cmd_refresh_session_send(void *, struct buffer *); -void cmd_refresh_session_recv(void **, struct buffer *); -void cmd_refresh_session_free(void *); - -struct cmd_refresh_session_data { - int flag_all; -}; - -const struct cmd_entry cmd_refresh_session_entry = { - "refresh-session", "refresh", "[-a]", - 0, - cmd_refresh_session_parse, - cmd_refresh_session_exec, - cmd_refresh_session_send, - cmd_refresh_session_recv, - cmd_refresh_session_free -}; - -int -cmd_refresh_session_parse(void **ptr, int argc, char **argv, char **cause) -{ - struct cmd_refresh_session_data *data; - int opt; - - *ptr = data = xmalloc(sizeof *data); - data->flag_all = 0; - - while ((opt = getopt(argc, argv, "a")) != EOF) { - switch (opt) { - case 'a': - data->flag_all = 1; - break; - default: - goto usage; - } - } - argc -= optind; - argv += optind; - if (argc != 0) - goto usage; - - return (0); - -usage: - usage(cause, "%s %s", - cmd_refresh_session_entry.name, cmd_refresh_session_entry.usage); - - cmd_refresh_session_free(data); - return (-1); -} - -void -cmd_refresh_session_exec(void *ptr, struct cmd_ctx *ctx) -{ - struct cmd_refresh_session_data *data = ptr, std = { 0 }; - struct client *c; - u_int i; - - if (data == NULL) - data = &std; - - if (data->flag_all) { - for (i = 0; i < ARRAY_LENGTH(&clients); i++) { - c = ARRAY_ITEM(&clients, i); - if (c == NULL || c->session != ctx->session) - continue; - server_redraw_client(c); - } - } else if (ctx->flags & CMD_KEY) - server_redraw_client(ctx->client); - - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); -} - -void -cmd_refresh_session_send(void *ptr, struct buffer *b) -{ - struct cmd_refresh_session_data *data = ptr; - - buffer_write(b, data, sizeof *data); -} - -void -cmd_refresh_session_recv(void **ptr, struct buffer *b) -{ - struct cmd_refresh_session_data *data; - - *ptr = data = xmalloc(sizeof *data); - buffer_read(b, data, sizeof *data); -} - -void -cmd_refresh_session_free(void *ptr) -{ - struct cmd_refresh_session_data *data = ptr; - - xfree(data); -} diff --git a/cmd-rename-session.c b/cmd-rename-session.c index a5601d5b..ae28eec6 100644 --- a/cmd-rename-session.c +++ b/cmd-rename-session.c @@ -1,4 +1,4 @@ -/* $Id: cmd-rename-session.c,v 1.2 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-rename-session.c,v 1.3 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -39,7 +39,7 @@ struct cmd_rename_session_data { const struct cmd_entry cmd_rename_session_entry = { "rename-session", "rename", "new-name", - 0, + CMD_NOCLIENT, cmd_rename_session_parse, cmd_rename_session_exec, cmd_rename_session_send, @@ -90,8 +90,8 @@ cmd_rename_session_exec(void *ptr, struct cmd_ctx *ctx) xfree(ctx->session->name); ctx->session->name = xstrdup(data->newname); - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } void diff --git a/cmd-rename-window.c b/cmd-rename-window.c index 8ee986ed..ba2f4fad 100644 --- a/cmd-rename-window.c +++ b/cmd-rename-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-rename-window.c,v 1.12 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-rename-window.c,v 1.13 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -40,7 +40,7 @@ struct cmd_rename_window_data { const struct cmd_entry cmd_rename_window_entry = { "rename-window", "renamew", "[-i index] new-name", - 0, + CMD_NOCLIENT, cmd_rename_window_parse, cmd_rename_window_exec, cmd_rename_window_send, @@ -111,8 +111,8 @@ cmd_rename_window_exec(void *ptr, struct cmd_ctx *ctx) server_status_session(ctx->session); - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } void diff --git a/cmd-select-window.c b/cmd-select-window.c index 11af68e9..16329ecf 100644 --- a/cmd-select-window.c +++ b/cmd-select-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-select-window.c,v 1.9 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-select-window.c,v 1.10 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -39,7 +39,7 @@ struct cmd_select_window_data { const struct cmd_entry cmd_select_window_entry = { "select-window", "selectw", "index", - 0, + CMD_NOCLIENT, cmd_select_window_parse, cmd_select_window_exec, cmd_select_window_send, @@ -117,8 +117,8 @@ cmd_select_window_exec(void *ptr, struct cmd_ctx *ctx) break; } - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } void diff --git a/cmd-send-prefix.c b/cmd-send-prefix.c index af426c78..1dc9ae02 100644 --- a/cmd-send-prefix.c +++ b/cmd-send-prefix.c @@ -1,4 +1,4 @@ -/* $Id: cmd-send-prefix.c,v 1.4 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-send-prefix.c,v 1.5 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -42,11 +42,9 @@ const struct cmd_entry cmd_send_prefix_entry = { void cmd_send_prefix_exec(unused void *ptr, struct cmd_ctx *ctx) { - struct window *w = ctx->client->session->curw->window; + input_translate_key( + ctx->client->session->curw->window->out, prefix_key); - if (ctx->flags & CMD_KEY) - input_translate_key(w->out, prefix_key); - - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } diff --git a/cmd-set-option.c b/cmd-set-option.c index 4e0c7c44..e6a89432 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-option.c,v 1.12 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-set-option.c,v 1.13 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -41,7 +41,7 @@ struct cmd_set_option_data { const struct cmd_entry cmd_set_option_entry = { "set-option", "set", "option value", - CMD_NOSESSION, + CMD_NOCLIENT|CMD_NOSESSION, cmd_set_option_parse, cmd_set_option_exec, cmd_set_option_send, @@ -198,8 +198,8 @@ cmd_set_option_exec(void *ptr, unused struct cmd_ctx *ctx) return; } - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } void diff --git a/cmd-swap-window.c b/cmd-swap-window.c index 4a02622d..66480ebf 100644 --- a/cmd-swap-window.c +++ b/cmd-swap-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-swap-window.c,v 1.2 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-swap-window.c,v 1.3 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -42,7 +42,7 @@ struct cmd_swap_window_data { const struct cmd_entry cmd_swap_window_entry = { "swap-window", "swapw", "[-i index] name index", - 0, + CMD_NOCLIENT, cmd_swap_window_parse, cmd_swap_window_exec, cmd_swap_window_send, @@ -155,8 +155,8 @@ cmd_swap_window_exec(void *ptr, struct cmd_ctx *ctx) if (src != dst) server_redraw_session(dst); - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } void diff --git a/cmd-unbind-key.c b/cmd-unbind-key.c index b7b53c6d..86a795a4 100644 --- a/cmd-unbind-key.c +++ b/cmd-unbind-key.c @@ -1,4 +1,4 @@ -/* $Id: cmd-unbind-key.c,v 1.6 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-unbind-key.c,v 1.7 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -38,7 +38,7 @@ struct cmd_unbind_key_data { const struct cmd_entry cmd_unbind_key_entry = { "unbind-key", "unbind", "key", - CMD_NOSESSION, + CMD_NOCLIENT|CMD_NOSESSION, cmd_unbind_key_parse, cmd_unbind_key_exec, cmd_unbind_key_send, @@ -91,8 +91,8 @@ cmd_unbind_key_exec(void *ptr, unused struct cmd_ctx *ctx) key_bindings_remove(data->key); - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } void diff --git a/cmd-unlink-window.c b/cmd-unlink-window.c index 948d07c9..9ed48104 100644 --- a/cmd-unlink-window.c +++ b/cmd-unlink-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-unlink-window.c,v 1.3 2007-11-13 09:53:47 nicm Exp $ */ +/* $Id: cmd-unlink-window.c,v 1.4 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -38,8 +38,8 @@ struct cmd_unlink_window_data { }; const struct cmd_entry cmd_unlink_window_entry = { - "unlink-window", "unlinkw", "[-i index", - 0, + "unlink-window", "unlinkw", "[-i index]", + CMD_NOCLIENT, cmd_unlink_window_parse, cmd_unlink_window_exec, cmd_unlink_window_send, @@ -128,8 +128,8 @@ cmd_unlink_window_exec(void *ptr, struct cmd_ctx *ctx) server_redraw_client(c); } - if (!(ctx->flags & CMD_KEY)) - server_write_client(ctx->client, MSG_EXIT, NULL, 0); + if (ctx->cmdclient != NULL) + server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } void diff --git a/cmd.c b/cmd.c index 82c53831..084f6bf8 100644 --- a/cmd.c +++ b/cmd.c @@ -1,4 +1,4 @@ -/* $Id: cmd.c,v 1.27 2007-11-16 13:23:59 nicm Exp $ */ +/* $Id: cmd.c,v 1.28 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -26,7 +26,7 @@ const struct cmd_entry *cmd_table[] = { &cmd_attach_session_entry, &cmd_bind_key_entry, - &cmd_detach_session_entry, + &cmd_detach_client_entry, &cmd_has_session_entry, &cmd_kill_session_entry, &cmd_kill_window_entry, @@ -40,7 +40,7 @@ const struct cmd_entry *cmd_table[] = { &cmd_new_window_entry, &cmd_next_window_entry, &cmd_previous_window_entry, - &cmd_refresh_session_entry, + &cmd_refresh_client_entry, &cmd_rename_session_entry, &cmd_rename_window_entry, &cmd_select_window_entry, diff --git a/key-bindings.c b/key-bindings.c index 72b89c9a..23d4c869 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -1,4 +1,4 @@ -/* $Id: key-bindings.c,v 1.12 2007-10-26 12:29:07 nicm Exp $ */ +/* $Id: key-bindings.c,v 1.13 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -79,8 +79,8 @@ key_bindings_init(void) const struct cmd_entry *entry; void (*fn)(void **, int); } table[] = { - { 'D', &cmd_detach_session_entry, NULL }, - { 'd', &cmd_detach_session_entry, NULL }, + { 'D', &cmd_detach_client_entry, NULL }, + { 'd', &cmd_detach_client_entry, NULL }, { 'S', &cmd_list_sessions_entry, NULL }, { 's', &cmd_list_sessions_entry, NULL }, { 'W', &cmd_list_windows_entry, NULL }, @@ -105,15 +105,10 @@ key_bindings_init(void) { '7', &cmd_select_window_entry, cmd_select_window_default }, { '8', &cmd_select_window_entry, cmd_select_window_default }, { '9', &cmd_select_window_entry, cmd_select_window_default }, - { 'R', &cmd_refresh_session_entry, NULL }, - { 'r', &cmd_refresh_session_entry, NULL }, + { 'R', &cmd_refresh_client_entry, NULL }, + { 'r', &cmd_refresh_client_entry, NULL }, { '&', &cmd_kill_window_entry, NULL }, { META, &cmd_send_prefix_entry, NULL }, -/* - { 'I', &cmd_windo_info_entry }, - { 'i', &cmd_window_info_entry }, - { META, &cmd_meta_entry_entry }, -*/ }; u_int i; struct cmd *cmd; @@ -164,7 +159,7 @@ key_bindings_error(struct cmd_ctx *ctx, const char *fmt, ...) void key_bindings_print(struct cmd_ctx *ctx, const char *fmt, ...) { - struct client *c = ctx->client; + struct client *c = ctx->cmdclient; struct hdr hdr; va_list ap; char *msg; @@ -219,11 +214,12 @@ key_bindings_dispatch(int key, struct client *c) return; ctx.session = c->session; + ctx.client = c; ctx.error = key_bindings_error; ctx.print = key_bindings_print; - ctx.client = c; + ctx.cmdclient = NULL; ctx.flags = CMD_KEY; cmd_exec(bd->cmd, &ctx); diff --git a/server-msg.c b/server-msg.c index ae25a84c..7c132d7a 100644 --- a/server-msg.c +++ b/server-msg.c @@ -1,4 +1,4 @@ -/* $Id: server-msg.c,v 1.30 2007-10-26 12:29:07 nicm Exp $ */ +/* $Id: server-msg.c,v 1.31 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -84,7 +84,7 @@ server_msg_fn_command_error(struct cmd_ctx *ctx, const char *fmt, ...) xvasprintf(&msg, fmt, ap); va_end(ap); - server_write_client(ctx->client, MSG_ERROR, msg, strlen(msg)); + server_write_client(ctx->cmdclient, MSG_ERROR, msg, strlen(msg)); xfree(msg); } @@ -98,7 +98,7 @@ server_msg_fn_command_print(struct cmd_ctx *ctx, const char *fmt, ...) xvasprintf(&msg, fmt, ap); va_end(ap); - server_write_client(ctx->client, MSG_PRINT, msg, strlen(msg)); + server_write_client(ctx->cmdclient, MSG_PRINT, msg, strlen(msg)); xfree(msg); } @@ -108,12 +108,14 @@ server_msg_fn_command(struct hdr *hdr, struct client *c) struct msg_command_data data; struct cmd_ctx ctx; struct cmd *cmd; - char *name, *cause; + char *name, *client, *cause; + u_int i; if (hdr->size < sizeof data) fatalx("bad MSG_COMMAND size"); buffer_read(c->in, &data, sizeof data); name = cmd_recv_string(c->in); + client = cmd_recv_string(c->in); cmd = cmd_recv(c->in); log_debug("got command %s from client %d", cmd->entry->name, c->fd); @@ -121,21 +123,53 @@ server_msg_fn_command(struct hdr *hdr, struct client *c) ctx.error = server_msg_fn_command_error; ctx.print = server_msg_fn_command_print; - ctx.client = c; + ctx.cmdclient = c; ctx.flags = 0; if (data.pid != -1 && (cmd->entry->flags & CMD_CANTNEST)) { - server_msg_fn_command_error(&ctx, "sessions should be nested " - "with care. unset $TMUX to force"); + server_msg_fn_command_error(&ctx, "sessions " + "should be nested with care. unset $TMUX to force"); goto out; } - if (cmd->entry->flags & CMD_NOSESSION) - ctx.session = NULL; - else { - ctx.session = server_extract_session(&data, name, &cause); + ctx.client = NULL; + if (cmd->entry->flags & CMD_NOCLIENT) { + if (client != NULL) { + server_msg_fn_command_error(&ctx, + "%s: cannot specify a client", cmd->entry->name); + goto out; + } + } else { + if (client == NULL) { + server_msg_fn_command_error(&ctx, "%s: must " + "specify a client: %s", cmd->entry->name, client); + goto out; + } + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + /* XXX fnmatch, multi clients etc */ + c = ARRAY_ITEM(&clients, i); + if (strcmp(client, c->tty) == 0) + ctx.client = c; + } + if (ctx.client == NULL) { + server_msg_fn_command_error(&ctx, "%s: " + "client not found: %s", cmd->entry->name, client); + goto out; + } + } + + ctx.session = server_extract_session(&data, name, &cause); + if (cmd->entry->flags & CMD_NOSESSION) { + if (ctx.session != NULL) { + server_msg_fn_command_error(&ctx, + "%s: cannot specify a session", cmd->entry->name); + goto out; + } else + xfree(cause); + } else { if (ctx.session == NULL) { - server_msg_fn_command_error(&ctx, "%s", cause); + server_msg_fn_command_error( + &ctx, "%s: %s", cmd->entry->name, cause); xfree(cause); goto out; } diff --git a/tmux.1 b/tmux.1 index f6cfb7cf..af08ef1a 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1,4 +1,4 @@ -.\" $Id: tmux.1,v 1.13 2007-11-12 20:46:46 nicm Exp $ +.\" $Id: tmux.1,v 1.14 2007-11-16 21:12:31 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -24,6 +24,7 @@ .Nm tmux .Bk -words .Op Fl vV +.Op Fl c Ar client-tty .Op Fl S Ar socket-path .Op Fl s Ar session-name .Ar command @@ -50,8 +51,14 @@ Communication takes place through a socket, by default placed in .Pp The options are as follows: .Bl -tag -width "XXXXXXXXXXXX" +.It Fl c Ar client-tty +Apply command to the client on the given tty. +Clients may be listed with the +.Ic list-clients +command (see below). +This option does not apply to all commands. .It Fl S Ar socket-path -This specifies an alternative path to the server socket. +Specify an alternative path to the server socket. The default is .Pa /tmp/tmux-UID , where @@ -138,13 +145,11 @@ Bind key .Ar key to .Ar command . -.It Xo Ic detach-session -.Op Fl a +.It Xo Ic detach-client .Xc .D1 (alias: Ic detach ) -Detach the current client if bound to a key; otherwise, if -.Fl a -is given, detach all clients attached to the session. +Detach the current client if bound to a key, or the specified client with +.Fl c . .It Xo Ic has-session .Xc .D1 (alias: Ic has ) @@ -255,14 +260,12 @@ Move to the next window in the session. .Xc .D1 (alias: Ic prev ) Move to the previous window in the session. -.It Xo Ic refresh-session -.Op Fl a +.It Xo Ic refresh-client .Xc .D1 (alias: Ic refresh ) -Refresh the display of clients attached to a session. -If bound to a key, only the current client is refreshed; otherwise if -.Fl a -is given, all clients attached to the session is refreshed. +Refresh the current client if bound to a key, or a single client if one given +with +.Fl c . .It Xo Ic rename-session .Ar new-name .Xc diff --git a/tmux.c b/tmux.c index b6ba1533..b47b9025 100644 --- a/tmux.c +++ b/tmux.c @@ -1,4 +1,4 @@ -/* $Id: tmux.c,v 1.40 2007-11-12 15:12:08 nicm Exp $ */ +/* $Id: tmux.c,v 1.41 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -52,17 +52,19 @@ usage(char **ptr, const char *fmt, ...) char *msg; va_list ap; +#define USAGE \ + "usage: %s [-v] [-S socket-path] [-s session-name] [-c client-tty]" if (fmt == NULL) { - xasprintf(ptr, - "usage: %s [-v] [-S path] command [flags]", __progname); + xasprintf(ptr, USAGE " command [flags]", __progname); } else { va_start(ap, fmt); xvasprintf(&msg, fmt, ap); va_end(ap); - xasprintf(ptr, "usage: %s [-v] [-S path] %s", __progname, msg); + xasprintf(ptr, USAGE " %s", __progname, msg); xfree(msg); } +#undef USAGE } void @@ -173,12 +175,16 @@ main(int argc, char **argv) struct hdr hdr; const char *shell; struct passwd *pw; - char *path, rpath[MAXPATHLEN], *cause, *name; + char *client, *path, *name, *cause; + char rpath[MAXPATHLEN]; int n, opt; - path = name = NULL; - while ((opt = getopt(argc, argv, "S:s:vV")) != EOF) { + client = path = name = NULL; + while ((opt = getopt(argc, argv, "c:S:s:vV")) != EOF) { switch (opt) { + case 'c': + client = xstrdup(optarg); + break; case 'S': path = xstrdup(optarg); break; @@ -244,6 +250,7 @@ main(int argc, char **argv) exit(1); b = buffer_create(BUFSIZ); cmd_send_string(b, name); + cmd_send_string(b, client); cmd_send(cmd, b); cmd_free(cmd); diff --git a/tmux.h b/tmux.h index 9934a4b6..fac858a3 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.79 2007-11-12 15:12:08 nicm Exp $ */ +/* $Id: tmux.h,v 1.80 2007-11-16 21:12:31 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -488,6 +488,8 @@ struct client_ctx { /* Key/command line command. */ struct cmd_ctx { + struct client *cmdclient; + struct client *client; struct session *session; @@ -505,7 +507,8 @@ struct cmd_entry { #define CMD_STARTSERVER 0x1 #define CMD_NOSESSION 0x2 -#define CMD_CANTNEST 0x4 +#define CMD_NOCLIENT 0x4 +#define CMD_CANTNEST 0x8 int flags; int (*parse)(void **, int, char **, char **); @@ -569,7 +572,7 @@ void cmd_send_string(struct buffer *, const char *); char *cmd_recv_string(struct buffer *); extern const struct cmd_entry cmd_attach_session_entry; extern const struct cmd_entry cmd_bind_key_entry; -extern const struct cmd_entry cmd_detach_session_entry; +extern const struct cmd_entry cmd_detach_client_entry; extern const struct cmd_entry cmd_has_session_entry; extern const struct cmd_entry cmd_kill_session_entry; extern const struct cmd_entry cmd_kill_window_entry; @@ -583,7 +586,7 @@ extern const struct cmd_entry cmd_new_session_entry; extern const struct cmd_entry cmd_new_window_entry; extern const struct cmd_entry cmd_next_window_entry; extern const struct cmd_entry cmd_previous_window_entry; -extern const struct cmd_entry cmd_refresh_session_entry; +extern const struct cmd_entry cmd_refresh_client_entry; extern const struct cmd_entry cmd_rename_session_entry; extern const struct cmd_entry cmd_rename_window_entry; extern const struct cmd_entry cmd_select_window_entry;