Revision: 2537
          http://tmux.svn.sourceforge.net/tmux/?rev=2537&view=rev
Author:   tcunha
Date:     2011-07-03 21:52:50 +0000 (Sun, 03 Jul 2011)

Log Message:
-----------
Sync OpenBSD patchset 927:

Allow the initial context on prompts to be set with the new -I option to
command-prompt. From Tiago Cunha.

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

Modified: trunk/cmd-command-prompt.c
===================================================================
--- trunk/cmd-command-prompt.c  2011-07-03 21:51:17 UTC (rev 2536)
+++ trunk/cmd-command-prompt.c  2011-07-03 21:52:50 UTC (rev 2537)
@@ -1,4 +1,4 @@
-/* $Id: cmd-command-prompt.c,v 1.31 2011-05-22 16:26:38 tcunha Exp $ */
+/* $Id$ */
 
 /*
  * Copyright (c) 2008 Nicholas Marriott <n...@users.sourceforge.net>
@@ -20,6 +20,7 @@
 
 #include <ctype.h>
 #include <string.h>
+#include <time.h>
 
 #include "tmux.h"
 
@@ -36,8 +37,8 @@
 
 const struct cmd_entry cmd_command_prompt_entry = {
        "command-prompt", NULL,
-       "p:t:", 0, 1,
-       CMD_TARGET_CLIENT_USAGE " [-p prompts] [template]",
+       "I:p:t:", 0, 1,
+       "[-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " [template]",
        0,
        cmd_command_prompt_key_binding,
        NULL,
@@ -46,6 +47,8 @@
 
 struct cmd_command_prompt_cdata {
        struct client   *c;
+       char            *inputs;
+       char            *next_input;
        char            *next_prompt;
        char            *prompts;
        char            *template;
@@ -79,9 +82,10 @@
 cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
 {
        struct args                     *args = self->args;
-       const char                      *prompts;
+       const char                      *inputs, *prompts;
        struct cmd_command_prompt_cdata *cdata;
        struct client                   *c;
+       char                            *input = NULL;
        char                            *prompt, *prompt_replaced, *ptr;
        size_t                           n;
 
@@ -94,6 +98,8 @@
        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;
@@ -103,8 +109,7 @@
        else
                cdata->template = xstrdup("%1");
 
-       prompts = args_get(args, 'p');
-       if (prompts != NULL)
+       if ((prompts = args_get(args, 'p')) != NULL)
                cdata->prompts = xstrdup(prompts);
        else if (args->argc != 0) {
                n = strcspn(cdata->template, " ,");
@@ -112,6 +117,7 @@
        } else
                cdata->prompts = xstrdup(":");
 
+       /* Get first prompt. */
        cdata->next_prompt = cdata->prompts;
        ptr = strsep(&cdata->next_prompt, ",");
        if (prompts == NULL)
@@ -122,8 +128,22 @@
                xasprintf(&prompt, "%s ", prompt_replaced);
                xfree(prompt_replaced);
        }
-       status_prompt_set(c, prompt, cmd_command_prompt_callback,
+
+       /* 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);
+       }
+
+       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);
@@ -136,29 +156,43 @@
        struct client                   *c = cdata->c;
        struct cmd_list                 *cmdlist;
        struct cmd_ctx                   ctx;
-       char                            *cause, *newtempl, *prompt, *ptr;
-       char                            *prompt_replaced;
+       char                            *cause, *new_template, *prompt;
+       char                            *prompt_replaced, *ptr, *input = NULL;
 
        if (s == NULL)
                return (0);
 
-       newtempl = cmd_template_replace(cdata->template, s, cdata->idx);
+       new_template = cmd_template_replace(cdata->template, s, cdata->idx);
        xfree(cdata->template);
-       cdata->template = newtempl;
+       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) {
                prompt_replaced = status_replace(c, NULL, NULL, NULL, ptr,
                    time(NULL), 0);
                xasprintf(&prompt, "%s ", prompt_replaced);
-               status_prompt_update(c, prompt);
 
+               /* 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);
+               }
+
+               status_prompt_update(c, prompt, input);
+
+               if (input != NULL)
+                       xfree(input);
                xfree(prompt_replaced);
                xfree(prompt);
+
                cdata->idx++;
                return (1);
        }
 
-       if (cmd_string_parse(newtempl, &cmdlist, &cause) != 0) {
+       if (cmd_string_parse(new_template, &cmdlist, &cause) != 0) {
                if (cause != NULL) {
                        *cause = toupper((u_char) *cause);
                        status_message_set(c, "%s", cause);
@@ -189,6 +223,8 @@
 {
        struct cmd_command_prompt_cdata *cdata = data;
 
+       if (cdata->inputs != NULL)
+               xfree(cdata->inputs);
        if (cdata->prompts != NULL)
                xfree(cdata->prompts);
        if (cdata->template != NULL)

Modified: trunk/cmd-confirm-before.c
===================================================================
--- trunk/cmd-confirm-before.c  2011-07-03 21:51:17 UTC (rev 2536)
+++ trunk/cmd-confirm-before.c  2011-07-03 21:52:50 UTC (rev 2537)
@@ -1,4 +1,4 @@
-/* $Id: cmd-confirm-before.c,v 1.13 2011-01-07 14:45:34 tcunha Exp $ */
+/* $Id$ */
 
 /*
  * Copyright (c) 2009 Tiago Cunha <m...@tiagocunha.org>
@@ -87,9 +87,8 @@
        cdata = xmalloc(sizeof *cdata);
        cdata->cmd = xstrdup(args->argv[0]);
        cdata->c = c;
-       status_prompt_set(cdata->c, buf,
-           cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
-           PROMPT_SINGLE);
+       status_prompt_set(cdata->c, buf, NULL, cmd_confirm_before_callback,
+           cmd_confirm_before_free, cdata, PROMPT_SINGLE);
 
        xfree(buf);
        return (1);

Modified: trunk/status.c
===================================================================
--- trunk/status.c      2011-07-03 21:51:17 UTC (rev 2536)
+++ trunk/status.c      2011-07-03 21:52:50 UTC (rev 2537)
@@ -1,4 +1,4 @@
-/* $Id: status.c,v 1.160 2011-05-05 10:02:36 tcunha Exp $ */
+/* $Id$ */
 
 /*
  * Copyright (c) 2007 Nicholas Marriott <n...@users.sourceforge.net>
@@ -815,7 +815,7 @@
 
 /* Enable status line prompt. */
 void
-status_prompt_set(struct client *c, const char *msg,
+status_prompt_set(struct client *c, const char *msg, const char *input,
     int (*callbackfn)(void *, const char *), void (*freefn)(void *),
     void *data, int flags)
 {
@@ -826,8 +826,11 @@
 
        c->prompt_string = xstrdup(msg);
 
-       c->prompt_buffer = xstrdup("");
-       c->prompt_index = 0;
+       if (input != NULL)
+               c->prompt_buffer = xstrdup(input);
+       else
+               c->prompt_buffer = xstrdup("");
+       c->prompt_index = strlen(c->prompt_buffer);
 
        c->prompt_callbackfn = callbackfn;
        c->prompt_freefn = freefn;
@@ -871,13 +874,17 @@
 
 /* Update status line prompt with a new prompt string. */
 void
-status_prompt_update(struct client *c, const char *msg)
+status_prompt_update(struct client *c, const char *msg, const char *input)
 {
        xfree(c->prompt_string);
        c->prompt_string = xstrdup(msg);
 
-       *c->prompt_buffer = '\0';
-       c->prompt_index = 0;
+       xfree(c->prompt_buffer);
+       if (input != NULL)
+               c->prompt_buffer = xstrdup(input);
+       else
+               c->prompt_buffer = xstrdup("");
+       c->prompt_index = strlen(c->prompt_buffer);
 
        c->prompt_hindex = 0;
 

Modified: trunk/tmux.1
===================================================================
--- trunk/tmux.1        2011-07-03 21:51:17 UTC (rev 2536)
+++ trunk/tmux.1        2011-07-03 21:52:50 UTC (rev 2537)
@@ -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: June 5 2011 $
+.Dd $Mdocdate: July 2 2011 $
 .Dt TMUX 1
 .Os
 .Sh NAME
@@ -2635,6 +2635,7 @@
 Commands related to the status line are as follows:
 .Bl -tag -width Ds
 .It Xo Ic command-prompt
+.Op Fl I Ar inputs
 .Op Fl p Ar prompts
 .Op Fl t Ar target-client
 .Op Ar template
@@ -2647,6 +2648,9 @@
 If
 .Ar template
 is specified, it is used as the command.
+If present,
+.Fl I
+is a comma-separated list of the initial text for each prompt.
 If
 .Fl p
 is given,
@@ -2657,7 +2661,10 @@
 if it is present, or
 .Ql \&:
 if not.
-The
+.Pp
+Both
+.Ar inputs
+and
 .Ar prompts
 may contain the special character sequences supported by the
 .Ic status-left

Modified: trunk/tmux.h
===================================================================
--- trunk/tmux.h        2011-07-03 21:51:17 UTC (rev 2536)
+++ trunk/tmux.h        2011-07-03 21:52:50 UTC (rev 2537)
@@ -1700,12 +1700,12 @@
 void printflike2 status_message_set(struct client *, const char *, ...);
 void    status_message_clear(struct client *);
 int     status_message_redraw(struct client *);
-void    status_prompt_set(struct client *, const char *,
+void    status_prompt_set(struct client *, const char *, const char *,
             int (*)(void *, const char *), void (*)(void *), void *, int);
 void    status_prompt_clear(struct client *);
 int     status_prompt_redraw(struct client *);
 void    status_prompt_key(struct client *, int);
-void    status_prompt_update(struct client *, const char *);
+void    status_prompt_update(struct client *, const char *, const char *);
 
 /* resize.c */
 void    recalculate_sizes(void);


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