Changeset 5184:6241f5669264

Show
Ignore:
Timestamp:
2007-07-08 18:27:35 (18 months ago)
Author:
David Champion <dgc@…>
Branch:
HEAD
Message:

This patch implements the "%* " notation, which is analogous to "%> "
but gives precedence to the right side instead of to the left when the
fill length is zero. The default $pager_format is updated to use it so
that %P is always available at the edge of the screen.

Files:
9 modified

Legend:

Unmodified
Added
Removed
  • commands.c

    r5011 r5184  
    284284  { 
    285285    mutt_format_string (prompt, sizeof (prompt), 
    286                         0, COLS-extra_space, 0, 0, 
     286                        0, COLS-extra_space, FMT_LEFT, 0, 
    287287                        scratch, sizeof (scratch), 0); 
    288288    safe_strcat (prompt, sizeof (prompt), "...?"); 
  • curs_lib.c

    r5048 r5184  
    293293  dprint (1, (debugfile, "%s\n", scratch)); 
    294294  mutt_format_string (Errorbuf, sizeof (Errorbuf), 
    295                       0, COLS-2, 0, 0, scratch, sizeof (scratch), 0); 
     295                      0, COLS-2, FMT_LEFT, 0, scratch, sizeof (scratch), 0); 
    296296 
    297297  if (!option (OPTKEEPQUIET)) 
     
    318318 
    319319  mutt_format_string (Errorbuf, sizeof (Errorbuf), 
    320                       0, COLS-2, 0, 0, scratch, sizeof (scratch), 0); 
     320                      0, COLS-2, FMT_LEFT, 0, scratch, sizeof (scratch), 0); 
    321321 
    322322  if (!option (OPTKEEPQUIET)) 
     
    642642void mutt_format_string (char *dest, size_t destlen, 
    643643                         int min_width, int max_width, 
    644                          int right_justify, char m_pad_char, 
     644                         int justify, char m_pad_char, 
    645645                         const char *s, size_t n, 
    646646                         int arboreal) 
     
    689689  if (w <= 0) 
    690690    *p = '\0'; 
    691   else if (right_justify) 
     691  else if (justify == FMT_RIGHT)        /* right justify */ 
    692692  { 
    693693    p[w] = '\0'; 
     
    697697      dest[w] = m_pad_char; 
    698698  } 
    699   else 
     699  else if (justify == FMT_CENTER)       /* center */ 
     700  { 
     701    char *savedp = p; 
     702    int half = (w+1) / 2; /* half of cushion space */ 
     703 
     704    p[w] = '\0'; 
     705 
     706    /* move str to center of buffer */ 
     707    while (--p >= dest) 
     708      p[half] = *p; 
     709 
     710    /* fill rhs */ 
     711    p = savedp + half; 
     712    while (--w >= half) 
     713      *p++ = m_pad_char; 
     714 
     715    /* fill lhs */ 
     716    while (half--) 
     717      dest[half] = m_pad_char; 
     718  } 
     719  else                                  /* left justify */ 
    700720  { 
    701721    while (--w >= 0) 
     
    719739                             int arboreal) 
    720740{ 
    721   int right_justify = 1; 
     741  int justify = FMT_RIGHT; 
    722742  char *p; 
    723743  int min_width; 
     
    725745 
    726746  if (*prefix == '-') 
    727     ++prefix, right_justify = 0; 
     747    ++prefix, justify = FMT_LEFT; 
     748  else if (*prefix == '=') 
     749    ++prefix, justify = FMT_CENTER; 
    728750  min_width = strtol (prefix, &p, 10); 
    729751  if (*p == '.') 
     
    736758 
    737759  mutt_format_string (dest, destlen, min_width, max_width, 
    738                       right_justify, ' ', s, mutt_strlen (s), arboreal); 
     760                      justify, ' ', s, mutt_strlen (s), arboreal); 
    739761} 
    740762 
     
    757779/* 
    758780 * mutt_paddstr (n, s) is almost equivalent to 
    759  * mutt_format_string (bigbuf, big, n, n, 0, ' ', s, big, 0), addstr (bigbuf) 
     781 * mutt_format_string (bigbuf, big, n, n, FMT_LEFT, ' ', s, big, 0), addstr (bigbuf) 
    760782 */ 
    761783 
  • doc/manual.xml.head

    r5059 r5184  
    32563256argument, or you can remove all hooks of a specific type by saying 
    32573257something like <literal>unhook send-hook</literal>. 
     3258</para> 
     3259 
     3260</sect1> 
     3261 
     3262<sect1 id="formatstrings"> 
     3263<title>Format Strings</title> 
     3264 
     3265<para> 
     3266Format strings are a general concept you'll find in several locations 
     3267through the mutt configuration, especially in the 
     3268<link linkend="index-format">&dollar;index&lowbar;format"</link>, 
     3269<link linkend="pager-format">&dollar;pager&lowbar;format"</link>, 
     3270<link linkend="status-format">&dollar;status&lowbar;format"</link>, 
     3271and other ``*_format'' variables. These can be very straightforward, 
     3272and it's quite possible you already know how to use them. 
     3273</para> 
     3274 
     3275<para> 
     3276The most basic format string element is a percent symbol followed 
     3277by another character. For example, <literal>%s</literal> 
     3278represents a message's Subject: header in the <link 
     3279linkend="index-format">&dollar;index&lowbar;format"</link> variable. The 
     3280``expandos'' available are documented with each format variable, but 
     3281there are general modifiers available with all formatting expandos, 
     3282too. Those are our concern here. 
     3283</para> 
     3284 
     3285<para> 
     3286Some of the modifers are borrowed right out of C (though you might 
     3287know them from Perl, Python, shell, or another langugage). These are 
     3288the [-]m.n modifiers, as in <literal>%-12.12s</literal>. As with 
     3289such programming languages, these modifiers allow you to specify the 
     3290minumum and maximum size of the resulting string, as well as its 
     3291justification. If the ``-'' sign follows the percent, the string will 
     3292be left-justified instead of right-justified. If there's a number 
     3293immediately following that, it's the minimum amount of space the 
     3294formatted string will occupy -- if it's naturally smaller than that, it 
     3295will be padded out with spaces.  If a decimal point and another number 
     3296follow, that's the maximum space allowable -- the string will not be 
     3297permitted to exceed that width, no matter its natural size. Each of 
     3298these three elements is optional, so that all these are legal format 
     3299strings: 
     3300<literal>%-12s</literal> 
     3301<literal>%4c</literal> 
     3302<literal>%.15F</literal> 
     3303<literal>%-12.15L</literal> 
     3304</para> 
     3305 
     3306<para> 
     3307Mutt adds some other modifiers to format strings. If you use an equals 
     3308symbol (<literal>=</literal>) as a numeric prefix (like the minus 
     3309above), it will force the string to be centered within its minimum 
     3310space range. For example, <literal>%=14y</literal> will reserve 14 
     3311characters for the %y expansion -- that's the X-Label: header, in 
     3312<literal>&dollar;index&lowbar;format</literal>. If the expansion 
     3313results in a string less than 14 characters, it will be centered in a 
     331414-character space.  If the X-Label for a message were "test", that 
     3315expansion would look like ``     test     ''. 
     3316</para> 
     3317 
     3318<para> 
     3319There are two very little-known modifiers that affect the way that an 
     3320expando is replaced. If there is an underline (``&lowbar;'') character 
     3321between any format modifiers (as above) and the expando letter, it will 
     3322expands in all lower case. And if you use a colon (``:''), it will 
     3323replace all decimal points with underlines. 
    32583324</para> 
    32593325 
  • init.h

    r5139 r5184  
    226226  ** .dt %>X .dd right justify the rest of the string and pad with character "X" 
    227227  ** .dt %|X .dd pad to the end of the line with character "X" 
     228  ** .dt %*X .dd soft-fill with character "X" as pad 
    228229  ** .de 
     230  ** For an explanation of `soft-fill', see the ``$$index_format'' documentation. 
    229231  */ 
    230232  { "attach_sep",       DT_STR,  R_NONE, UL &AttachSep, UL "\n" }, 
     
    615617  ** .dt %>X .dd right justify the rest of the string and pad with character "X" 
    616618  ** .dt %|X .dd pad to the end of the line with character "X" 
     619  ** .dt %*X .dd soft-fill with character "X" as pad 
    617620  ** .de 
     621  ** For an explanation of `soft-fill', see the ``$$index_format'' documentation. 
    618622  */ 
    619623  { "followup_to",      DT_BOOL, R_NONE, OPTFOLLOWUPTO, 1 }, 
     
    10371041  ** .dt %>X    .dd right justify the rest of the string and pad with character "X" 
    10381042  ** .dt %|X    .dd pad to the end of the line with character "X" 
     1043  ** .dt %*X    .dd soft-fill with character "X" as pad 
    10391044  ** .de 
     1045  ** `Soft-fill' deserves some explanation. Normal right-justification 
     1046  ** will print everything to the left of the %>, displaying padding and 
     1047  ** the whatever lies to the right only if there's room. By contrast, 
     1048  ** soft-fill gives priority to the right-hand side, guaranteeing space 
     1049  ** to display it and showing padding only if there's still room. If 
     1050  ** necessary, soft-fill will eat text leftwards to make room for 
     1051  ** rightward text. 
    10401052  ** .pp 
    10411053  ** See also: ``$$to_chars''. 
     
    13531365  ** at the top of the next page (0 lines of context). 
    13541366  */ 
    1355   { "pager_format",     DT_STR,  R_PAGER, UL &PagerFmt, UL "-%Z- %C/%m: %-20.20n   %s%> -- (%P)" }, 
     1367  { "pager_format",     DT_STR,  R_PAGER, UL &PagerFmt, UL "-%Z- %C/%m: %-20.20n   %s%* -- (%P)" }, 
    13561368  /* 
    13571369  ** .pp 
     
    27402752  ** .dt %>X .dd right justify the rest of the string and pad with "X" 
    27412753  ** .dt %|X .dd pad to the end of the line with "X" 
     2754  ** .dt %*X .dd soft-fill with character "X" as pad 
    27422755  ** .de 
     2756  ** For an explanation of `soft-fill', see the ``$$index_format'' documentation. 
    27432757  ** .pp 
    27442758  ** * = can be optionally printed if nonzero 
  • lib.h

    r5092 r5184  
    8585# define MIN(a,b) ((a) < (b) ? (a) : (b)) 
    8686 
     87/* For mutt_format_string() justifications */ 
     88/* Making left 0 and center -1 is of course completely nonsensical, but 
     89 * it retains compatibility for any patches that call mutt_format_string. 
     90 * Once patches are updated to use FMT_*, these can be made sane. */ 
     91#define FMT_LEFT        0 
     92#define FMT_RIGHT       1 
     93#define FMT_CENTER      -1 
    8794 
    8895#define FOREVER while (1) 
  • menu.c

    r4898 r5184  
    161161  int cols = COLS - shift; 
    162162 
    163   mutt_format_string (s, n, cols, cols, 0, ' ', scratch, mutt_strlen (scratch), 1); 
     163  mutt_format_string (s, n, cols, cols, FMT_LEFT, ' ', scratch, mutt_strlen (scratch), 1); 
    164164  s[n - 1] = 0; 
    165165  FREE (&scratch); 
  • muttlib.c

    r5148 r5184  
    10001000  char prefix[SHORT_STRING], buf[LONG_STRING], *cp, *wptr = dest, ch; 
    10011001  char ifstring[SHORT_STRING], elsestring[SHORT_STRING]; 
     1002  char remainder[LONG_STRING]; 
    10021003  size_t wlen, count, len, wid; 
    10031004  pid_t pid; 
     
    11481149        count = 0; 
    11491150        while (count < sizeof (prefix) && 
    1150                (isdigit ((unsigned char) *src) || *src == '.' || *src == '-')) 
     1151               (isdigit ((unsigned char) *src) || *src == '.' || *src == '-' || *src == '=')) 
    11511152        { 
    11521153          *cp++ = *src++; 
     
    12401241        break; /* skip rest of input */ 
    12411242      } 
     1243      /* soft fill */ 
     1244      else if (ch == '*') 
     1245      { 
     1246        int space; 
     1247 
     1248        /* truncate to fit remainder, pad with chr. */ 
     1249        ch = *src++;    /* pad chr */ 
     1250        mutt_FormatString (remainder, sizeof(remainder), 0, src, callback, 
     1251          data, flags); 
     1252 
     1253        len = mutt_strlen(remainder); 
     1254        space = COLS - wlen - len;      /* bytes remaining unformatted */ 
     1255 
     1256        /* if space > 0, this is space that needs to be filled */ 
     1257        if (space > 0) 
     1258        { 
     1259          memset(wptr, ch, space); 
     1260          wptr += space; 
     1261          wlen += space; 
     1262        } 
     1263 
     1264        /* if space < 0, there's not enough room for remainder -- backtrack */ 
     1265        else if (space < 0) { 
     1266          wptr += space; 
     1267          wlen += space; 
     1268          if (wlen < 0) { 
     1269            wptr = dest; 
     1270            wlen = 0; 
     1271          } 
     1272        } 
     1273 
     1274        /* Since remainder is already formatted, copy it * 
     1275         * in.  This prevents having to format it twice. */ 
     1276        if (len > COLS) 
     1277          len = COLS; 
     1278        memcpy(wptr, remainder, len); 
     1279        wptr += len; 
     1280        wlen += len; 
     1281      } 
     1282 
    12421283      else 
    12431284      { 
  • query.c

    r5010 r5184  
    205205  mutt_format_string (buf2, sizeof (buf2), 
    206206                      FirstColumn + 2, FirstColumn + 2, 
    207                       0, ' ', table[num].data->name, 
     207                      FMT_LEFT, ' ', table[num].data->name, 
    208208                      mutt_strlen (table[num].data->name), 0); 
    209209 
  • recvcmd.c

    r4343 r5184  
    183183  { 
    184184    mutt_format_string (prompt, sizeof (prompt) - 4, 
    185                         0, COLS-extra_space, 0, 0, 
     185                        0, COLS-extra_space, FMT_LEFT, 0, 
    186186                        prompt, sizeof (prompt), 0); 
    187187    safe_strcat (prompt, sizeof (prompt), "...?");