Make client -c and -t handling common in cmd-queue.c and try to be

clearer about whether the client is the target client (must have a
session) or not.
This commit is contained in:
nicm
2020-04-13 20:51:57 +00:00
parent 187277eaad
commit 3f7f9a0e20
29 changed files with 239 additions and 237 deletions

View File

@ -45,7 +45,7 @@ const struct cmd_entry cmd_display_message_entry = {
.target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.flags = CMD_AFTERHOOK|CMD_CLIENT_CFLAG|CMD_CLIENT_CANFAIL,
.exec = cmd_display_message_exec
};
@ -62,7 +62,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmd_find_state *target = cmdq_get_target(item);
struct client *c, *target_c;
struct client *tc = cmdq_get_target_client(item), *c;
struct session *s = target->s;
struct winlink *wl = target->wl;
struct window_pane *wp = target->wp;
@ -97,17 +97,16 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
* 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;
if (tc != NULL && tc->session == s)
c = tc;
else
target_c = cmd_find_best_client(s);
c = cmd_find_best_client(s);
if (args_has(args, 'v'))
flags = FORMAT_VERBOSE;
else
flags = 0;
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, flags);
format_defaults(ft, target_c, s, wl, wp);
format_defaults(ft, c, s, wl, wp);
if (args_has(args, 'a')) {
format_each(ft, cmd_display_message_each, item);
@ -117,8 +116,8 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
msg = format_expand_time(ft, template);
if (args_has(args, 'p'))
cmdq_print(item, "%s", msg);
else if (c != NULL)
status_message_set(c, "%s", msg);
else if (tc != NULL)
status_message_set(tc, "%s", msg);
free(msg);
format_free(ft);