From 12eceaf2b3ef2b028a55d8ad11951be700be0446 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 14 May 2020 10:35:26 +0100 Subject: [PATCH] Expand target from client and use it to expand the prompt. --- cmd-command-prompt.c | 6 ++++-- cmd-confirm-before.c | 6 ++++-- cmd-queue.c | 3 +-- mode-tree.c | 4 ++-- status.c | 11 +++++++---- tmux.h | 5 +++-- window-customize.c | 11 ++++++----- window-tree.c | 9 +++++---- 8 files changed, 32 insertions(+), 23 deletions(-) diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c index b8e3bd5c..c82235c5 100644 --- a/cmd-command-prompt.c +++ b/cmd-command-prompt.c @@ -66,6 +66,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); struct client *tc = cmdq_get_target_client(item); + struct cmd_find_state *target = cmdq_get_target(item); const char *inputs, *prompts; struct cmd_command_prompt_cdata *cdata; char *prompt, *ptr, *input = NULL; @@ -125,8 +126,9 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item) cdata->flags |= PROMPT_WINDOW; else if (args_has(args, 'T')) cdata->flags |= PROMPT_TARGET; - status_prompt_set(tc, prompt, input, cmd_command_prompt_callback, - cmd_command_prompt_free, cdata, cdata->flags); + status_prompt_set(tc, target, prompt, input, + cmd_command_prompt_callback, cmd_command_prompt_free, cdata, + cdata->flags); free(prompt); return (CMD_RETURN_NORMAL); diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index 0d881178..0c562836 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -56,6 +56,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item) struct args *args = cmd_get_args(self); struct cmd_confirm_before_data *cdata; struct client *tc = cmdq_get_target_client(item); + struct cmd_find_state *target = cmdq_get_target(item); char *cmd, *copy, *new_prompt, *ptr; const char *prompt; @@ -71,8 +72,9 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item) cdata = xmalloc(sizeof *cdata); cdata->cmd = xstrdup(args->argv[0]); - status_prompt_set(tc, new_prompt, NULL, cmd_confirm_before_callback, - cmd_confirm_before_free, cdata, PROMPT_SINGLE); + status_prompt_set(tc, target, new_prompt, NULL, + cmd_confirm_before_callback, cmd_confirm_before_free, cdata, + PROMPT_SINGLE); free(new_prompt); return (CMD_RETURN_NORMAL); diff --git a/cmd-queue.c b/cmd-queue.c index a40053a6..6bc6d0d2 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -522,7 +522,7 @@ cmdq_find_flag(struct cmdq_item *item, struct cmd_find_state *fs, const char *value; if (flag->flag == 0) { - cmd_find_clear_state(fs, 0); + cmd_find_from_client(fs, item->target_client, 0); return (CMD_RETURN_NORMAL); } @@ -610,7 +610,6 @@ cmdq_fire_command(struct cmdq_item *item) if (retval == CMD_RETURN_ERROR) goto out; - retval = entry->exec(cmd, item); if (retval == CMD_RETURN_ERROR) goto out; diff --git a/mode-tree.c b/mode-tree.c index 131830d6..a523478e 100644 --- a/mode-tree.c +++ b/mode-tree.c @@ -1125,7 +1125,7 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key, case '/': case '\023': /* C-s */ mtd->references++; - status_prompt_set(c, "(search) ", "", + status_prompt_set(c, NULL, "(search) ", "", mode_tree_search_callback, mode_tree_search_free, mtd, PROMPT_NOFORMAT); break; @@ -1134,7 +1134,7 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key, break; case 'f': mtd->references++; - status_prompt_set(c, "(filter) ", mtd->filter, + status_prompt_set(c, NULL, "(filter) ", mtd->filter, mode_tree_filter_callback, mode_tree_filter_free, mtd, PROMPT_NOFORMAT); break; diff --git a/status.c b/status.c index b5fa0824..56af02f5 100644 --- a/status.c +++ b/status.c @@ -532,14 +532,17 @@ status_message_redraw(struct client *c) /* Enable status line prompt. */ void -status_prompt_set(struct client *c, const char *msg, const char *input, - prompt_input_cb inputcb, prompt_free_cb freecb, void *data, int flags) +status_prompt_set(struct client *c, struct cmd_find_state *fs, + const char *msg, const char *input, prompt_input_cb inputcb, + prompt_free_cb freecb, void *data, int flags) { struct format_tree *ft; char *tmp, *cp; - ft = format_create(c, NULL, FORMAT_NONE, 0); - format_defaults(ft, c, NULL, NULL, NULL); + if (fs != NULL) + ft = format_create_from_state(NULL, c, fs); + else + ft = format_create_defaults(NULL, c, NULL, NULL, NULL); if (input == NULL) input = ""; diff --git a/tmux.h b/tmux.h index 4c9d229f..2b88305a 100644 --- a/tmux.h +++ b/tmux.h @@ -2361,8 +2361,9 @@ void printflike(3, 4) status_message_set(struct client *, int, const char *, ...); void status_message_clear(struct client *); int status_message_redraw(struct client *); -void status_prompt_set(struct client *, const char *, const char *, - prompt_input_cb, prompt_free_cb, void *, int); +void status_prompt_set(struct client *, struct cmd_find_state *, + const char *, const char *, prompt_input_cb, prompt_free_cb, + void *, int); void status_prompt_clear(struct client *); int status_prompt_redraw(struct client *); int status_prompt_key(struct client *, key_code); diff --git a/window-customize.c b/window-customize.c index c74884d6..12c09cf6 100644 --- a/window-customize.c +++ b/window-customize.c @@ -1111,7 +1111,7 @@ window_customize_set_option(struct client *c, new_item->idx = idx; data->references++; - status_prompt_set(c, prompt, value, + status_prompt_set(c, NULL, prompt, value, window_customize_set_option_callback, window_customize_free_item_callback, new_item, PROMPT_NOFORMAT); @@ -1243,7 +1243,7 @@ window_customize_set_key(struct client *c, new_item->key = key; data->references++; - status_prompt_set(c, prompt, value, + status_prompt_set(c, NULL, prompt, value, window_customize_set_command_callback, window_customize_free_item_callback, new_item, PROMPT_NOFORMAT); @@ -1259,7 +1259,8 @@ window_customize_set_key(struct client *c, new_item->key = key; data->references++; - status_prompt_set(c, prompt, (bd->note == NULL ? "" : bd->note), + status_prompt_set(c, NULL, prompt, + (bd->note == NULL ? "" : bd->note), window_customize_set_note_callback, window_customize_free_item_callback, new_item, PROMPT_NOFORMAT); @@ -1398,7 +1399,7 @@ window_customize_key(struct window_mode_entry *wme, struct client *c, } else xasprintf(&prompt, "Unset option %s? ", item->name); data->references++; - status_prompt_set(c, prompt, "", + status_prompt_set(c, NULL, prompt, "", window_customize_unset_current_callback, window_customize_free_callback, data, PROMPT_SINGLE|PROMPT_NOFORMAT); @@ -1410,7 +1411,7 @@ window_customize_key(struct window_mode_entry *wme, struct client *c, break; xasprintf(&prompt, "Unset or unbind %u tagged? ", tagged); data->references++; - status_prompt_set(c, prompt, "", + status_prompt_set(c, NULL, prompt, "", window_customize_unset_tagged_callback, window_customize_free_callback, data, PROMPT_SINGLE|PROMPT_NOFORMAT); diff --git a/window-tree.c b/window-tree.c index b3ce8bb7..393b88a4 100644 --- a/window-tree.c +++ b/window-tree.c @@ -1234,7 +1234,7 @@ window_tree_key(struct window_mode_entry *wme, struct client *c, if (prompt == NULL) break; data->references++; - status_prompt_set(c, prompt, "", + status_prompt_set(c, NULL, prompt, "", window_tree_kill_current_callback, window_tree_command_free, data, PROMPT_SINGLE|PROMPT_NOFORMAT); free(prompt); @@ -1245,7 +1245,7 @@ window_tree_key(struct window_mode_entry *wme, struct client *c, break; xasprintf(&prompt, "Kill %u tagged? ", tagged); data->references++; - status_prompt_set(c, prompt, "", + status_prompt_set(c, NULL, prompt, "", window_tree_kill_tagged_callback, window_tree_command_free, data, PROMPT_SINGLE|PROMPT_NOFORMAT); free(prompt); @@ -1257,8 +1257,9 @@ window_tree_key(struct window_mode_entry *wme, struct client *c, else xasprintf(&prompt, "(current) "); data->references++; - status_prompt_set(c, prompt, "", window_tree_command_callback, - window_tree_command_free, data, PROMPT_NOFORMAT); + status_prompt_set(c, NULL, prompt, "", + window_tree_command_callback, window_tree_command_free, + data, PROMPT_NOFORMAT); free(prompt); break; case '\r':