Ah yes this was lost when we changed to just use the format aliases
code. Try this diff for now which lets you set a length limit when using
the full format. You'll want to use #{20:pane_title} instead of #20T.

diff --git a/format.c b/format.c
index 0845df6..7ed6fb2 100644
--- a/format.c
+++ b/format.c
@@ -18,6 +18,8 @@
 
 #include <sys/types.h>
 
+#include <ctype.h>
+#include <errno.h>
 #include <netdb.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -188,18 +190,30 @@ format_find(struct format_tree *ft, const char *key)
  * #{?blah,a,b} is replace with a if blah exists and is nonzero else b.
  */
 int
-format_replace(struct format_tree *ft,
-    const char *key, size_t keylen, char **buf, size_t *len, size_t *off)
+format_replace(struct format_tree *ft, const char *key, size_t keylen,
+    char **buf, size_t *len, size_t *off)
 {
-       char            *copy, *ptr;
+       char            *copy, *copy0, *endptr, *ptr;
        const char      *value;
        size_t           valuelen;
+       unsigned long    ul;
 
        /* Make a copy of the key. */
-       copy = xmalloc(keylen + 1);
+       copy0 = copy = xmalloc(keylen + 1);
        memcpy(copy, key, keylen);
        copy[keylen] = '\0';
 
+       /* Is there a length limit? */
+       if (isdigit(*copy)) {
+               errno = 0;
+               ul = strtoul(copy, &endptr, 10);
+               if (*endptr != ':' || (errno == ERANGE && ul == ULONG_MAX))
+                       ul = ULONG_MAX;
+               else
+                       copy = endptr + 1;
+       } else
+               ul = ULONG_MAX;
+
        /*
         * Is this a conditional? If so, check it exists and extract either the
         * first or second element. If not, look up the key directly.
@@ -230,6 +244,10 @@ format_replace(struct format_tree *ft,
        }
        valuelen = strlen(value);
 
+       /* Truncate the value if needed. */
+       if (valuelen > ul)
+               valuelen = ul;
+
        /* Expand the buffer and copy in the value. */
        while (*len - *off < valuelen + 1) {
                *buf = xrealloc(*buf, 2, *len);
@@ -238,11 +256,11 @@ format_replace(struct format_tree *ft,
        memcpy(*buf + *off, value, valuelen);
        *off += valuelen;
 
-       free(copy);
+       free(copy0);
        return (0);
 
 fail:
-       free(copy);
+       free(copy0);
        return (-1);
 }
 




On Fri, Aug 02, 2013 at 11:57:34AM -0400, Naseer Ahmed wrote:
>    This option used to work on tmux-1.8, now it just shows the full title.
>    set-option -gw window-status-format "#I:#20W#F"

> ------------------------------------------------------------------------------
> Get your SQL database under version control now!
> Version control is standard for application code, but databases havent 
> caught up. So what steps can you take to put your SQL databases under 
> version control? Why should you start doing it? Read more to find out.
> http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk

> _______________________________________________
> tmux-users mailing list
> tmux-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tmux-users


------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to