=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-command-prompt.c,v retrieving revision 1.38 retrieving revision 1.39 diff -c -r1.38 -r1.39 *** src/usr.bin/tmux/cmd-command-prompt.c 2016/10/16 19:04:05 1.38 --- src/usr.bin/tmux/cmd-command-prompt.c 2017/01/06 11:57:03 1.39 *************** *** 1,4 **** ! /* $OpenBSD: cmd-command-prompt.c,v 1.38 2016/10/16 19:04:05 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: cmd-command-prompt.c,v 1.39 2017/01/06 11:57:03 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott *************** *** 32,46 **** static enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmdq_item *); ! static int cmd_command_prompt_callback(void *, const char *); static void cmd_command_prompt_free(void *); const struct cmd_entry cmd_command_prompt_entry = { .name = "command-prompt", .alias = NULL, ! .args = { "1I:Np:t:", 0, 1 }, ! .usage = "[-1N] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " " "[template]", .tflag = CMD_CLIENT, --- 32,46 ---- static enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmdq_item *); ! static int cmd_command_prompt_callback(void *, const char *, int); static void cmd_command_prompt_free(void *); const struct cmd_entry cmd_command_prompt_entry = { .name = "command-prompt", .alias = NULL, ! .args = { "1iI:Np:t:", 0, 1 }, ! .usage = "[-1Ni] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " " "[template]", .tflag = CMD_CLIENT, *************** *** 51,60 **** struct cmd_command_prompt_cdata { struct client *c; char *inputs; char *next_input; ! char *next_prompt; char *prompts; char *template; int idx; }; --- 51,64 ---- struct cmd_command_prompt_cdata { struct client *c; + int flags; + char *inputs; char *next_input; ! char *prompts; + char *next_prompt; + char *template; int idx; }; *************** *** 73,86 **** if (c->prompt_string != NULL) return (CMD_RETURN_NORMAL); ! cdata = xmalloc(sizeof *cdata); cdata->c = c; ! cdata->idx = 1; cdata->inputs = NULL; cdata->next_input = NULL; ! cdata->next_prompt = NULL; cdata->prompts = NULL; cdata->template = NULL; if (args->argc != 0) cdata->template = xstrdup(args->argv[0]); --- 77,93 ---- if (c->prompt_string != NULL) return (CMD_RETURN_NORMAL); ! cdata = xcalloc(1, sizeof *cdata); cdata->c = c; ! cdata->inputs = NULL; cdata->next_input = NULL; ! cdata->prompts = NULL; + cdata->next_prompt = NULL; + cdata->template = NULL; + cdata->idx = 1; if (args->argc != 0) cdata->template = xstrdup(args->argv[0]); *************** *** 112,122 **** flags = 0; if (args_has(args, '1')) ! flags |= PROMPT_SINGLE; else if (args_has(args, 'N')) ! flags |= PROMPT_NUMERIC; status_prompt_set(c, prompt, input, cmd_command_prompt_callback, ! cmd_command_prompt_free, cdata, flags); free(prompt); return (CMD_RETURN_NORMAL); --- 119,131 ---- flags = 0; if (args_has(args, '1')) ! cdata->flags |= PROMPT_SINGLE; else if (args_has(args, 'N')) ! cdata->flags |= PROMPT_NUMERIC; ! else if (args_has(args, 'i')) ! cdata->flags |= PROMPT_INCREMENTAL; status_prompt_set(c, prompt, input, cmd_command_prompt_callback, ! cmd_command_prompt_free, cdata, cdata->flags); free(prompt); return (CMD_RETURN_NORMAL); *************** *** 134,140 **** } static int ! cmd_command_prompt_callback(void *data, const char *s) { struct cmd_command_prompt_cdata *cdata = data; struct client *c = cdata->c; --- 143,149 ---- } static int ! cmd_command_prompt_callback(void *data, const char *s, int done) { struct cmd_command_prompt_cdata *cdata = data; struct client *c = cdata->c; *************** *** 145,160 **** if (s == NULL) return (0); new_template = cmd_template_replace(cdata->template, s, cdata->idx); ! free(cdata->template); ! cdata->template = new_template; /* * Check if there are more prompts; if so, get its respective input * and update the prompt data. */ ! if ((ptr = strsep(&cdata->next_prompt, ",")) != NULL) { xasprintf(&prompt, "%s ", ptr); input = strsep(&cdata->next_input, ","); status_prompt_update(c, prompt, input); --- 154,173 ---- if (s == NULL) return (0); + if (done && (cdata->flags & PROMPT_INCREMENTAL)) + return (0); new_template = cmd_template_replace(cdata->template, s, cdata->idx); ! if (done) { ! free(cdata->template); ! cdata->template = new_template; ! } /* * Check if there are more prompts; if so, get its respective input * and update the prompt data. */ ! if (done && (ptr = strsep(&cdata->next_prompt, ",")) != NULL) { xasprintf(&prompt, "%s ", ptr); input = strsep(&cdata->next_input, ","); status_prompt_update(c, prompt, input); *************** *** 178,183 **** --- 191,198 ---- if (new_item != NULL) cmdq_append(c, new_item); + if (!done) + free(new_template); if (c->prompt_callbackfn != (void *)&cmd_command_prompt_callback) return (1); return (0);