Revision: 2547
          http://tmux.svn.sourceforge.net/tmux/?rev=2547&view=rev
Author:   tcunha
Date:     2011-07-08 08:42:03 +0000 (Fri, 08 Jul 2011)

Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/cmd-command-prompt.c
    trunk/cmd-confirm-before.c
    trunk/status.c
    trunk/tmux.1

Modified: trunk/cmd-command-prompt.c
===================================================================
--- trunk/cmd-command-prompt.c  2011-07-08 08:40:35 UTC (rev 2546)
+++ trunk/cmd-command-prompt.c  2011-07-08 08:42:03 UTC (rev 2547)
@@ -90,8 +90,7 @@
        const char                      *inputs, *prompts;
        struct cmd_command_prompt_cdata *cdata;
        struct client                   *c;
-       char                            *input = NULL;
-       char                            *prompt, *prompt_replaced, *ptr;
+       char                            *prompt, *ptr, *input = NULL;
        size_t                           n;
 
        if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
@@ -127,28 +126,18 @@
        ptr = strsep(&cdata->next_prompt, ",");
        if (prompts == NULL)
                prompt = xstrdup(ptr);
-       else {
-               prompt_replaced = status_replace(c, NULL, NULL, NULL, ptr,
-                   time(NULL), 0);
-               xasprintf(&prompt, "%s ", prompt_replaced);
-               xfree(prompt_replaced);
-       }
+       else
+               xasprintf(&prompt, "%s ", ptr);
 
        /* Get initial prompt input. */
        if ((inputs = args_get(args, 'I')) != NULL) {
                cdata->inputs = xstrdup(inputs);
                cdata->next_input = cdata->inputs;
-               ptr = strsep(&cdata->next_input, ",");
-
-               input = status_replace(c, NULL, NULL, NULL, ptr, time(NULL),
-                   0);
+               input = strsep(&cdata->next_input, ",");
        }
 
        status_prompt_set(c, prompt, input, cmd_command_prompt_callback,
            cmd_command_prompt_free, cdata, 0);
-
-       if (input != NULL)
-               xfree(input);
        xfree(prompt);
 
        return (0);
@@ -161,8 +150,8 @@
        struct client                   *c = cdata->c;
        struct cmd_list                 *cmdlist;
        struct cmd_ctx                   ctx;
-       char                            *cause, *new_template, *prompt;
-       char                            *prompt_replaced, *ptr, *input = NULL;
+       char                            *cause, *new_template, *prompt, *ptr;
+       char                            *input = NULL;
 
        if (s == NULL)
                return (0);
@@ -176,23 +165,11 @@
         * and update the prompt data.
         */
        if ((ptr = strsep(&cdata->next_prompt, ",")) != NULL) {
-               prompt_replaced = status_replace(c, NULL, NULL, NULL, ptr,
-                   time(NULL), 0);
-               xasprintf(&prompt, "%s ", prompt_replaced);
-
-               /* Find next input and expand special sequences. */
-               if ((ptr = strsep(&cdata->next_input, ",")) != NULL) {
-                       input = status_replace(c, NULL, NULL, NULL, ptr,
-                           time(NULL), 0);
-               }
-
+               xasprintf(&prompt, "%s ", ptr);
+               input = strsep(&cdata->next_input, ",");
                status_prompt_update(c, prompt, input);
 
-               if (input != NULL)
-                       xfree(input);
-               xfree(prompt_replaced);
                xfree(prompt);
-
                cdata->idx++;
                return (1);
        }

Modified: trunk/cmd-confirm-before.c
===================================================================
--- trunk/cmd-confirm-before.c  2011-07-08 08:40:35 UTC (rev 2546)
+++ trunk/cmd-confirm-before.c  2011-07-08 08:42:03 UTC (rev 2547)
@@ -33,8 +33,8 @@
 
 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 @@
        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 @@
        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 @@
        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);
 }
 

Modified: trunk/status.c
===================================================================
--- trunk/status.c      2011-07-08 08:40:35 UTC (rev 2546)
+++ trunk/status.c      2011-07-08 08:42:03 UTC (rev 2547)
@@ -824,12 +824,13 @@
        status_message_clear(c);
        status_prompt_clear(c);
 
-       c->prompt_string = xstrdup(msg);
+       c->prompt_string = status_replace(c, NULL, NULL, NULL, msg,
+           time(NULL), 0);
 
-       if (input != NULL)
-               c->prompt_buffer = xstrdup(input);
-       else
-               c->prompt_buffer = xstrdup("");
+       if (input == NULL)
+               input = "";
+       c->prompt_buffer = status_replace(c, NULL, NULL, NULL, input,
+           time(NULL), 0);
        c->prompt_index = strlen(c->prompt_buffer);
 
        c->prompt_callbackfn = callbackfn;
@@ -877,13 +878,14 @@
 status_prompt_update(struct client *c, const char *msg, const char *input)
 {
        xfree(c->prompt_string);
-       c->prompt_string = xstrdup(msg);
+       c->prompt_string = status_replace(c, NULL, NULL, NULL, msg,
+           time(NULL), 0);
 
        xfree(c->prompt_buffer);
-       if (input != NULL)
-               c->prompt_buffer = xstrdup(input);
-       else
-               c->prompt_buffer = xstrdup("");
+       if (input == NULL)
+               input = "";
+       c->prompt_buffer = status_replace(c, NULL, NULL, NULL, input,
+           time(NULL), 0);
        c->prompt_index = strlen(c->prompt_buffer);
 
        c->prompt_hindex = 0;

Modified: trunk/tmux.1
===================================================================
--- trunk/tmux.1        2011-07-08 08:40:35 UTC (rev 2546)
+++ trunk/tmux.1        2011-07-08 08:42:03 UTC (rev 2547)
@@ -14,7 +14,7 @@
 .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd $Mdocdate: July 3 2011 $
+.Dd $Mdocdate: July 8 2011 $
 .Dt TMUX 1
 .Os
 .Sh NAME
@@ -2694,12 +2694,23 @@
 .Ql %9
 .Pc .
 .It Xo Ic confirm-before
+.Op Fl p Ar prompt
 .Op Fl t Ar target-client
 .Ar command
 .Xc
 .D1 (alias: Ic confirm )
 Ask for confirmation before executing
 .Ar command .
+If
+.Fl p
+is given,
+.Ar prompt
+is the prompt to display; otherwise a prompt is constructed from
+.Ar command .
+It may contain the special character sequences supported by the
+.Ic status-left
+option.
+.Pp
 This command works only from inside
 .Nm .
 .It Xo Ic display-message


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
tmux-cvs mailing list
tmux-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to