[PATCH] soft-fill for format strings
I've been wanting this just about forever, and I finally had a chance to
code it up.
This patch implements what, for lack of a term, I'm calling "soft-fill"
inside format strings. The point is to make the field width of a token
variable, so that it might be greater than or less than the space
required for the full token expansion, but sufficient to permit the
remainder of the format string to fit onscreen.
Essentially, it allows mutt_FormatString() to look ahead from the
current token to the remainder of a format string, measure how long the
expanded text will be, and copy only so much of the current token's
expansion as will fit in the difference.
Perhaps it's best explained by a simple example. The syntax is "%=xy":
'=' is the soft-fill modifier, 'x' is the fill character, and 'y' is the
expando to take a variable size. If I put "%4C %[%y%m%d] %=.s [%F]" in
my index_format, then Mutt will copy all of the index number (%C) and
date (%[) to the left edge of the display, and all of the sender name to
the right edge, and will fill into the middle as much of the subject as
will fit in the space remaining:
34 030915 And now a word from your sponsor............. [Verisign Corporation]
35 030915 Re: Re: Re: Verisign are idiots and will be first agains [Angry Man]
The first message's subject was not long enough to fill all the empty
space between %[%y%m%d] and [%L], so it was padded out with ".". The
second was too long, so it was truncated.
Suggestions on a more pleasing syntax would be welcome, but this works
well enough for now.
--
-D. dgc@xxxxxxxxxxxx
University of Chicago > NSIT > VDN > ENSS > ENSA > You are here
. . . . . . .
always line up dots
--- mutt-1.5.4/PATCHES~ never
+++ mutt-1.5.4/PATCHES Wed Sep 17 00:41:09 CDT 2003
@@ -1,0 +1 @@
+patch-1.5.4.dgc.softfill.2
diff -ur mutt-1.5.4-dist/init.h mutt-1.5.4-softfill/init.h
--- mutt-1.5.4-dist/init.h Tue Mar 4 03:28:12 2003
+++ mutt-1.5.4-softfill/init.h Wed Sep 17 03:58:32 2003
@@ -214,6 +214,7 @@
** .dt %u .dd unlink (=to delete) flag
** .dt %>X .dd right justify the rest of the string and pad with character
"X"
** .dt %|X .dd pad to the end of the line with character "X"
+ ** .dt %=XY .dd soft-fill %Y, padding with character "X"
** .de
*/
{ "attach_sep", DT_STR, R_NONE, UL &AttachSep, UL "\n" },
@@ -552,6 +553,7 @@
** .dt %u .dd owner name (or numeric uid, if missing)
** .dt %>X .dd right justify the rest of the string and pad with character
"X"
** .dt %|X .dd pad to the end of the line with character "X"
+ ** .dt %=XY .dd soft-fill %Y, padding with character "X"
** .de
*/
{ "followup_to", DT_BOOL, R_NONE, OPTFOLLOWUPTO, 1 },
@@ -926,6 +928,7 @@
** function ``strftime''; a leading bang disables locales.
** .dt %>X .dd right justify the rest of the string and pad with
character "X"
** .dt %|X .dd pad to the end of the line with character "X"
+ ** .dt %=XY .dd soft-fill %Y, padding with character "X"
** .de
** .pp
** See also: ``$$to_chars''.
@@ -2413,6 +2416,7 @@
** .dt %V .dd currently active limit pattern, if any *
** .dt %>X .dd right justify the rest of the string and pad with "X"
** .dt %|X .dd pad to the end of the line with "X"
+ ** .dt %=XY .dd soft-fill %Y, padding with character "X"
** .de
** .pp
** * = can be optionally printed if nonzero
diff -ur mutt-1.5.4-dist/muttlib.c mutt-1.5.4-softfill/muttlib.c
--- mutt-1.5.4-dist/muttlib.c Tue Jan 21 06:25:21 2003
+++ mutt-1.5.4-softfill/muttlib.c Wed Sep 17 03:58:32 2003
@@ -906,9 +906,14 @@
unsigned long data, /* callback data */
format_flag flags) /* callback flags */
{
- char prefix[SHORT_STRING], buf[LONG_STRING], *cp, *wptr = dest, ch;
+ char prefix[SHORT_STRING], buf[LONG_STRING], *cp, *wptr = dest, ch, fmtch;
char ifstring[SHORT_STRING], elsestring[SHORT_STRING];
+ char remainder[LONG_STRING];
size_t wlen, count, len;
+ pid_t pid;
+ FILE *filter;
+ int n, dofilter = 0;
+ char *recycler;
prefix[0] = '\0';
destlen--; /* save room for the terminal \0 */
@@ -1028,6 +1033,45 @@
}
break; /* skip rest of input */
}
+ else if (ch == '=')
+ {
+ int space, used;
+
+ /* truncate to fit remainder, pad with chr. */
+ ch = *src++; /* pad chr */
+ fmtch = *src++; /* format chr to truncate */
+ mutt_FormatString (remainder, sizeof(remainder), src, callback,
+ data, flags);
+
+ len = mutt_strlen(remainder);
+ space = COLS - wlen - len;
+
+ if (space > 0)
+ {
+ src = callback (buf, sizeof (buf), fmtch, src, prefix, ifstring,
elsestring, data, flags);
+ memcpy (wptr, buf, space);
+ used = mutt_strlen(buf);
+
+ if (used > space)
+ used = space;
+
+ wptr += used;
+ wlen += used;
+
+ if (space > used)
+ {
+ memset (wptr, ch, space - used);
+ wptr += space - used;
+ wlen += space - used;
+ }
+
+ }
+
+ memcpy(wptr, remainder, len);
+ wptr += len;
+ wlen += len;
+ }
+
else
{
short tolower = 0;