summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-display-message.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2018-04-18 14:35:37 +0000
committernicm <nicm@openbsd.org>2018-04-18 14:35:37 +0000
commitb69086446f3dd70f2786f04bed3a4eb79f538baa (patch)
treefe0805d5ddcf84886ba02f94173bbb86df7d6291 /usr.bin/tmux/cmd-display-message.c
parentInclude source function name in grid_check_y logging. (diff)
downloadwireguard-openbsd-b69086446f3dd70f2786f04bed3a4eb79f538baa.tar.xz
wireguard-openbsd-b69086446f3dd70f2786f04bed3a4eb79f538baa.zip
Change how display-message uses the client. Originally it was only
intended as the target client where the message should be displayed but at some point (perhaps when -p was added), it was used for format expansion too. This means it can get a bit weird where you have client formats expanding for a client with a different current session than the target session. However, it is nice that display-message can be used to show information about a specific client. So change so that the -c client will be used if the session matches the target session (-t or default), otherwise the best client will be chosen.
Diffstat (limited to 'usr.bin/tmux/cmd-display-message.c')
-rw-r--r--usr.bin/tmux/cmd-display-message.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/usr.bin/tmux/cmd-display-message.c b/usr.bin/tmux/cmd-display-message.c
index c4aa3226bbd..aed48060550 100644
--- a/usr.bin/tmux/cmd-display-message.c
+++ b/usr.bin/tmux/cmd-display-message.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-display-message.c,v 1.42 2017/05/01 12:20:55 nicm Exp $ */
+/* $OpenBSD: cmd-display-message.c,v 1.43 2018/04/18 14:35:37 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -53,7 +53,7 @@ static enum cmd_retval
cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct client *c;
+ struct client *c, *target_c;
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
struct window_pane *wp = item->target.wp;
@@ -65,7 +65,6 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
cmdq_error(item, "only one of -F or argument must be given");
return (CMD_RETURN_ERROR);
}
- c = cmd_find_client(item, args_get(args, 'c'), 1);
template = args_get(args, 'F');
if (args->argc != 0)
@@ -73,14 +72,27 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
if (template == NULL)
template = DISPLAY_MESSAGE_TEMPLATE;
+ /*
+ * -c is intended to be the client where the message should be
+ * displayed if -p is not given. But it makes sense to use it for the
+ * formats too, assuming it matches the session. If it doesn't, use the
+ * best client for the session.
+ */
+ c = cmd_find_client(item, args_get(args, 'c'), 1);
+ if (c != NULL && c->session == s)
+ target_c = c;
+ else
+ target_c = cmd_find_best_client(s);
ft = format_create(item->client, item, FORMAT_NONE, 0);
- format_defaults(ft, c, s, wl, wp);
+ format_defaults(ft, target_c, s, wl, wp);
msg = format_expand_time(ft, template, time(NULL));
if (args_has(self->args, 'p'))
cmdq_print(item, "%s", msg);
- else if (c != NULL)
- status_message_set(c, "%s", msg);
+ else {
+ if (c != NULL)
+ status_message_set(c, "%s", msg);
+ }
free(msg);
format_free(ft);