diff options
author | Tiago Cunha <tcunha@gmx.com> | 2011-07-08 08:42:03 +0000 |
---|---|---|
committer | Tiago Cunha <tcunha@gmx.com> | 2011-07-08 08:42:03 +0000 |
commit | bba822105bb45ab998ebb7e8299ddc2b8989e672 (patch) | |
tree | 3901738866dabad26bc71ae16c2fceb4255ee16a /cmd-confirm-before.c | |
parent | dc2c174496532a915120c6fd12b26df742a3ee8e (diff) | |
download | rtmux-bba822105bb45ab998ebb7e8299ddc2b8989e672.tar.gz rtmux-bba822105bb45ab998ebb7e8299ddc2b8989e672.tar.bz2 rtmux-bba822105bb45ab998ebb7e8299ddc2b8989e672.zip |
Sync OpenBSD patchset 934:
Make confirm-before prompt customizable with -p option like
command-prompt. Also move responsibility for calling status_replace into
status_prompt_{set,update} and add #W and #P to the default kill-window
and kill-pane prompts. By Tiago Cunha.
Diffstat (limited to 'cmd-confirm-before.c')
-rw-r--r-- | cmd-confirm-before.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index eca3cd3f..159b938d 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -33,8 +33,8 @@ void cmd_confirm_before_free(void *); const struct cmd_entry cmd_confirm_before_entry = { "confirm-before", "confirm", - "t:", 1, 1, - CMD_TARGET_CLIENT_USAGE " command", + "p:t:", 1, 1, + "[-p prompt] " CMD_TARGET_CLIENT_USAGE " command", 0, cmd_confirm_before_key_binding, NULL, @@ -52,9 +52,11 @@ cmd_confirm_before_key_binding(struct cmd *self, int key) switch (key) { case '&': self->args = args_create(1, "kill-window"); + args_set(self->args, 'p', "kill-window #W? (y/n)"); break; case 'x': self->args = args_create(1, "kill-pane"); + args_set(self->args, 'p', "kill-pane #P? (y/n)"); break; default: self->args = args_create(0); @@ -68,7 +70,8 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx) struct args *args = self->args; struct cmd_confirm_before_data *cdata; struct client *c; - char *buf, *cmd, *ptr; + char *cmd, *copy, *new_prompt, *ptr; + const char *prompt; if (ctx->curclient == NULL) { ctx->error(ctx, "must be run interactively"); @@ -78,19 +81,23 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx) if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) return (-1); - ptr = xstrdup(args->argv[0]); - if ((cmd = strtok(ptr, " \t")) == NULL) - cmd = ptr; - xasprintf(&buf, "Confirm '%s'? (y/n) ", cmd); - xfree(ptr); + if ((prompt = args_get(args, 'p')) != NULL) + xasprintf(&new_prompt, "%s ", prompt); + else { + ptr = copy = xstrdup(args->argv[0]); + cmd = strsep(&ptr, " \t"); + xasprintf(&new_prompt, "Confirm '%s'? (y/n) ", cmd); + xfree(copy); + } cdata = xmalloc(sizeof *cdata); cdata->cmd = xstrdup(args->argv[0]); cdata->c = c; - status_prompt_set(cdata->c, buf, NULL, cmd_confirm_before_callback, - cmd_confirm_before_free, cdata, PROMPT_SINGLE); + status_prompt_set(cdata->c, new_prompt, NULL, + cmd_confirm_before_callback, cmd_confirm_before_free, cdata, + PROMPT_SINGLE); - xfree(buf); + xfree(new_prompt); return (1); } |