Expand target from client and use it to expand the prompt.

pull/2219/head
nicm 2020-05-16 16:16:07 +00:00
parent 72984c4834
commit c914abfa19
9 changed files with 36 additions and 28 deletions

View File

@ -66,6 +66,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
{ {
struct args *args = cmd_get_args(self); struct args *args = cmd_get_args(self);
struct client *tc = cmdq_get_target_client(item); struct client *tc = cmdq_get_target_client(item);
struct cmd_find_state *target = cmdq_get_target(item);
const char *inputs, *prompts; const char *inputs, *prompts;
struct cmd_command_prompt_cdata *cdata; struct cmd_command_prompt_cdata *cdata;
char *prompt, *ptr, *input = NULL; char *prompt, *ptr, *input = NULL;
@ -125,8 +126,9 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
cdata->flags |= PROMPT_WINDOW; cdata->flags |= PROMPT_WINDOW;
else if (args_has(args, 'T')) else if (args_has(args, 'T'))
cdata->flags |= PROMPT_TARGET; cdata->flags |= PROMPT_TARGET;
status_prompt_set(tc, prompt, input, cmd_command_prompt_callback, status_prompt_set(tc, target, prompt, input,
cmd_command_prompt_free, cdata, cdata->flags); cmd_command_prompt_callback, cmd_command_prompt_free, cdata,
cdata->flags);
free(prompt); free(prompt);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);

View File

@ -56,6 +56,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
struct args *args = cmd_get_args(self); struct args *args = cmd_get_args(self);
struct cmd_confirm_before_data *cdata; struct cmd_confirm_before_data *cdata;
struct client *tc = cmdq_get_target_client(item); struct client *tc = cmdq_get_target_client(item);
struct cmd_find_state *target = cmdq_get_target(item);
char *cmd, *copy, *new_prompt, *ptr; char *cmd, *copy, *new_prompt, *ptr;
const char *prompt; const char *prompt;
@ -71,8 +72,9 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
cdata = xmalloc(sizeof *cdata); cdata = xmalloc(sizeof *cdata);
cdata->cmd = xstrdup(args->argv[0]); cdata->cmd = xstrdup(args->argv[0]);
status_prompt_set(tc, new_prompt, NULL, cmd_confirm_before_callback, status_prompt_set(tc, target, new_prompt, NULL,
cmd_confirm_before_free, cdata, PROMPT_SINGLE); cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
PROMPT_SINGLE);
free(new_prompt); free(new_prompt);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);

View File

@ -522,7 +522,7 @@ cmdq_find_flag(struct cmdq_item *item, struct cmd_find_state *fs,
const char *value; const char *value;
if (flag->flag == 0) { if (flag->flag == 0) {
cmd_find_clear_state(fs, 0); cmd_find_from_client(fs, item->target_client, 0);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
@ -610,7 +610,6 @@ cmdq_fire_command(struct cmdq_item *item)
if (retval == CMD_RETURN_ERROR) if (retval == CMD_RETURN_ERROR)
goto out; goto out;
retval = entry->exec(cmd, item); retval = entry->exec(cmd, item);
if (retval == CMD_RETURN_ERROR) if (retval == CMD_RETURN_ERROR)
goto out; goto out;

View File

@ -1125,7 +1125,7 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
case '/': case '/':
case '\023': /* C-s */ case '\023': /* C-s */
mtd->references++; mtd->references++;
status_prompt_set(c, "(search) ", "", status_prompt_set(c, NULL, "(search) ", "",
mode_tree_search_callback, mode_tree_search_free, mtd, mode_tree_search_callback, mode_tree_search_free, mtd,
PROMPT_NOFORMAT); PROMPT_NOFORMAT);
break; break;
@ -1134,7 +1134,7 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
break; break;
case 'f': case 'f':
mtd->references++; 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, mode_tree_filter_callback, mode_tree_filter_free, mtd,
PROMPT_NOFORMAT); PROMPT_NOFORMAT);
break; break;

View File

@ -213,7 +213,6 @@ server_client_create(int fd)
c->queue = cmdq_new(); c->queue = cmdq_new();
c->tty.fd = -1; c->tty.fd = -1;
c->tty.sx = 80; c->tty.sx = 80;
c->tty.sy = 24; c->tty.sy = 24;
@ -272,7 +271,7 @@ server_client_open(struct client *c, char **cause)
void void
server_client_lost(struct client *c) server_client_lost(struct client *c)
{ {
struct client_file *cf; struct client_file *cf, *cf1;
c->flags |= CLIENT_DEAD; c->flags |= CLIENT_DEAD;
@ -280,7 +279,7 @@ server_client_lost(struct client *c)
status_prompt_clear(c); status_prompt_clear(c);
status_message_clear(c); status_message_clear(c);
RB_FOREACH(cf, client_files, &c->files) { RB_FOREACH_SAFE(cf, client_files, &c->files, cf1) {
cf->error = EINTR; cf->error = EINTR;
file_fire_done(cf); file_fire_done(cf);
} }
@ -2250,7 +2249,7 @@ server_client_set_flags(struct client *c, const char *flags)
} }
/*Get client flags. This is only flags useful to show to users. */ /* Get client flags. This is only flags useful to show to users. */
const char * const char *
server_client_get_flags(struct client *c) server_client_get_flags(struct client *c)
{ {

View File

@ -532,14 +532,17 @@ status_message_redraw(struct client *c)
/* Enable status line prompt. */ /* Enable status line prompt. */
void void
status_prompt_set(struct client *c, const char *msg, const char *input, status_prompt_set(struct client *c, struct cmd_find_state *fs,
prompt_input_cb inputcb, prompt_free_cb freecb, void *data, int flags) const char *msg, const char *input, prompt_input_cb inputcb,
prompt_free_cb freecb, void *data, int flags)
{ {
struct format_tree *ft; struct format_tree *ft;
char *tmp, *cp; char *tmp, *cp;
ft = format_create(c, NULL, FORMAT_NONE, 0); if (fs != NULL)
format_defaults(ft, c, NULL, NULL, NULL); ft = format_create_from_state(NULL, c, fs);
else
ft = format_create_defaults(NULL, c, NULL, NULL, NULL);
if (input == NULL) if (input == NULL)
input = ""; input = "";

7
tmux.h
View File

@ -1504,7 +1504,7 @@ struct client_file {
client_file_cb cb; client_file_cb cb;
void *data; void *data;
RB_ENTRY (client_file) entry; RB_ENTRY(client_file) entry;
}; };
RB_HEAD(client_files, client_file); RB_HEAD(client_files, client_file);
@ -2359,8 +2359,9 @@ void printflike(3, 4) status_message_set(struct client *, int, const char *,
...); ...);
void status_message_clear(struct client *); void status_message_clear(struct client *);
int status_message_redraw(struct client *); int status_message_redraw(struct client *);
void status_prompt_set(struct client *, const char *, const char *, void status_prompt_set(struct client *, struct cmd_find_state *,
prompt_input_cb, prompt_free_cb, void *, int); const char *, const char *, prompt_input_cb, prompt_free_cb,
void *, int);
void status_prompt_clear(struct client *); void status_prompt_clear(struct client *);
int status_prompt_redraw(struct client *); int status_prompt_redraw(struct client *);
int status_prompt_key(struct client *, key_code); int status_prompt_key(struct client *, key_code);

View File

@ -1111,7 +1111,7 @@ window_customize_set_option(struct client *c,
new_item->idx = idx; new_item->idx = idx;
data->references++; data->references++;
status_prompt_set(c, prompt, value, status_prompt_set(c, NULL, prompt, value,
window_customize_set_option_callback, window_customize_set_option_callback,
window_customize_free_item_callback, new_item, window_customize_free_item_callback, new_item,
PROMPT_NOFORMAT); PROMPT_NOFORMAT);
@ -1243,7 +1243,7 @@ window_customize_set_key(struct client *c,
new_item->key = key; new_item->key = key;
data->references++; data->references++;
status_prompt_set(c, prompt, value, status_prompt_set(c, NULL, prompt, value,
window_customize_set_command_callback, window_customize_set_command_callback,
window_customize_free_item_callback, new_item, window_customize_free_item_callback, new_item,
PROMPT_NOFORMAT); PROMPT_NOFORMAT);
@ -1259,7 +1259,8 @@ window_customize_set_key(struct client *c,
new_item->key = key; new_item->key = key;
data->references++; 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_set_note_callback,
window_customize_free_item_callback, new_item, window_customize_free_item_callback, new_item,
PROMPT_NOFORMAT); PROMPT_NOFORMAT);
@ -1398,7 +1399,7 @@ window_customize_key(struct window_mode_entry *wme, struct client *c,
} else } else
xasprintf(&prompt, "Unset option %s? ", item->name); xasprintf(&prompt, "Unset option %s? ", item->name);
data->references++; data->references++;
status_prompt_set(c, prompt, "", status_prompt_set(c, NULL, prompt, "",
window_customize_unset_current_callback, window_customize_unset_current_callback,
window_customize_free_callback, data, window_customize_free_callback, data,
PROMPT_SINGLE|PROMPT_NOFORMAT); PROMPT_SINGLE|PROMPT_NOFORMAT);
@ -1410,7 +1411,7 @@ window_customize_key(struct window_mode_entry *wme, struct client *c,
break; break;
xasprintf(&prompt, "Unset or unbind %u tagged? ", tagged); xasprintf(&prompt, "Unset or unbind %u tagged? ", tagged);
data->references++; data->references++;
status_prompt_set(c, prompt, "", status_prompt_set(c, NULL, prompt, "",
window_customize_unset_tagged_callback, window_customize_unset_tagged_callback,
window_customize_free_callback, data, window_customize_free_callback, data,
PROMPT_SINGLE|PROMPT_NOFORMAT); PROMPT_SINGLE|PROMPT_NOFORMAT);

View File

@ -1234,7 +1234,7 @@ window_tree_key(struct window_mode_entry *wme, struct client *c,
if (prompt == NULL) if (prompt == NULL)
break; break;
data->references++; data->references++;
status_prompt_set(c, prompt, "", status_prompt_set(c, NULL, prompt, "",
window_tree_kill_current_callback, window_tree_command_free, window_tree_kill_current_callback, window_tree_command_free,
data, PROMPT_SINGLE|PROMPT_NOFORMAT); data, PROMPT_SINGLE|PROMPT_NOFORMAT);
free(prompt); free(prompt);
@ -1245,7 +1245,7 @@ window_tree_key(struct window_mode_entry *wme, struct client *c,
break; break;
xasprintf(&prompt, "Kill %u tagged? ", tagged); xasprintf(&prompt, "Kill %u tagged? ", tagged);
data->references++; data->references++;
status_prompt_set(c, prompt, "", status_prompt_set(c, NULL, prompt, "",
window_tree_kill_tagged_callback, window_tree_command_free, window_tree_kill_tagged_callback, window_tree_command_free,
data, PROMPT_SINGLE|PROMPT_NOFORMAT); data, PROMPT_SINGLE|PROMPT_NOFORMAT);
free(prompt); free(prompt);
@ -1257,8 +1257,9 @@ window_tree_key(struct window_mode_entry *wme, struct client *c,
else else
xasprintf(&prompt, "(current) "); xasprintf(&prompt, "(current) ");
data->references++; data->references++;
status_prompt_set(c, prompt, "", window_tree_command_callback, status_prompt_set(c, NULL, prompt, "",
window_tree_command_free, data, PROMPT_NOFORMAT); window_tree_command_callback, window_tree_command_free,
data, PROMPT_NOFORMAT);
free(prompt); free(prompt);
break; break;
case '\r': case '\r':