Changeset 5184:6241f5669264
Legend:
- Unmodified
- Added
- Removed
-
commands.c
r5011 r5184 284 284 { 285 285 mutt_format_string (prompt, sizeof (prompt), 286 0, COLS-extra_space, 0, 0,286 0, COLS-extra_space, FMT_LEFT, 0, 287 287 scratch, sizeof (scratch), 0); 288 288 safe_strcat (prompt, sizeof (prompt), "...?"); -
curs_lib.c
r5048 r5184 293 293 dprint (1, (debugfile, "%s\n", scratch)); 294 294 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); 296 296 297 297 if (!option (OPTKEEPQUIET)) … … 318 318 319 319 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); 321 321 322 322 if (!option (OPTKEEPQUIET)) … … 642 642 void mutt_format_string (char *dest, size_t destlen, 643 643 int min_width, int max_width, 644 int right_justify, char m_pad_char,644 int justify, char m_pad_char, 645 645 const char *s, size_t n, 646 646 int arboreal) … … 689 689 if (w <= 0) 690 690 *p = '\0'; 691 else if ( right_justify)691 else if (justify == FMT_RIGHT) /* right justify */ 692 692 { 693 693 p[w] = '\0'; … … 697 697 dest[w] = m_pad_char; 698 698 } 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 */ 700 720 { 701 721 while (--w >= 0) … … 719 739 int arboreal) 720 740 { 721 int right_justify = 1;741 int justify = FMT_RIGHT; 722 742 char *p; 723 743 int min_width; … … 725 745 726 746 if (*prefix == '-') 727 ++prefix, right_justify = 0; 747 ++prefix, justify = FMT_LEFT; 748 else if (*prefix == '=') 749 ++prefix, justify = FMT_CENTER; 728 750 min_width = strtol (prefix, &p, 10); 729 751 if (*p == '.') … … 736 758 737 759 mutt_format_string (dest, destlen, min_width, max_width, 738 right_justify, ' ', s, mutt_strlen (s), arboreal);760 justify, ' ', s, mutt_strlen (s), arboreal); 739 761 } 740 762 … … 757 779 /* 758 780 * 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) 760 782 */ 761 783 -
doc/manual.xml.head
r5059 r5184 3256 3256 argument, or you can remove all hooks of a specific type by saying 3257 3257 something like <literal>unhook send-hook</literal>. 3258 </para> 3259 3260 </sect1> 3261 3262 <sect1 id="formatstrings"> 3263 <title>Format Strings</title> 3264 3265 <para> 3266 Format strings are a general concept you'll find in several locations 3267 through the mutt configuration, especially in the 3268 <link linkend="index-format">$index_format"</link>, 3269 <link linkend="pager-format">$pager_format"</link>, 3270 <link linkend="status-format">$status_format"</link>, 3271 and other ``*_format'' variables. These can be very straightforward, 3272 and it's quite possible you already know how to use them. 3273 </para> 3274 3275 <para> 3276 The most basic format string element is a percent symbol followed 3277 by another character. For example, <literal>%s</literal> 3278 represents a message's Subject: header in the <link 3279 linkend="index-format">$index_format"</link> variable. The 3280 ``expandos'' available are documented with each format variable, but 3281 there are general modifiers available with all formatting expandos, 3282 too. Those are our concern here. 3283 </para> 3284 3285 <para> 3286 Some of the modifers are borrowed right out of C (though you might 3287 know them from Perl, Python, shell, or another langugage). These are 3288 the [-]m.n modifiers, as in <literal>%-12.12s</literal>. As with 3289 such programming languages, these modifiers allow you to specify the 3290 minumum and maximum size of the resulting string, as well as its 3291 justification. If the ``-'' sign follows the percent, the string will 3292 be left-justified instead of right-justified. If there's a number 3293 immediately following that, it's the minimum amount of space the 3294 formatted string will occupy -- if it's naturally smaller than that, it 3295 will be padded out with spaces. If a decimal point and another number 3296 follow, that's the maximum space allowable -- the string will not be 3297 permitted to exceed that width, no matter its natural size. Each of 3298 these three elements is optional, so that all these are legal format 3299 strings: 3300 <literal>%-12s</literal> 3301 <literal>%4c</literal> 3302 <literal>%.15F</literal> 3303 <literal>%-12.15L</literal> 3304 </para> 3305 3306 <para> 3307 Mutt adds some other modifiers to format strings. If you use an equals 3308 symbol (<literal>=</literal>) as a numeric prefix (like the minus 3309 above), it will force the string to be centered within its minimum 3310 space range. For example, <literal>%=14y</literal> will reserve 14 3311 characters for the %y expansion -- that's the X-Label: header, in 3312 <literal>$index_format</literal>. If the expansion 3313 results in a string less than 14 characters, it will be centered in a 3314 14-character space. If the X-Label for a message were "test", that 3315 expansion would look like `` test ''. 3316 </para> 3317 3318 <para> 3319 There are two very little-known modifiers that affect the way that an 3320 expando is replaced. If there is an underline (``_'') character 3321 between any format modifiers (as above) and the expando letter, it will 3322 expands in all lower case. And if you use a colon (``:''), it will 3323 replace all decimal points with underlines. 3258 3324 </para> 3259 3325 -
init.h
r5139 r5184 226 226 ** .dt %>X .dd right justify the rest of the string and pad with character "X" 227 227 ** .dt %|X .dd pad to the end of the line with character "X" 228 ** .dt %*X .dd soft-fill with character "X" as pad 228 229 ** .de 230 ** For an explanation of `soft-fill', see the ``$$index_format'' documentation. 229 231 */ 230 232 { "attach_sep", DT_STR, R_NONE, UL &AttachSep, UL "\n" }, … … 615 617 ** .dt %>X .dd right justify the rest of the string and pad with character "X" 616 618 ** .dt %|X .dd pad to the end of the line with character "X" 619 ** .dt %*X .dd soft-fill with character "X" as pad 617 620 ** .de 621 ** For an explanation of `soft-fill', see the ``$$index_format'' documentation. 618 622 */ 619 623 { "followup_to", DT_BOOL, R_NONE, OPTFOLLOWUPTO, 1 }, … … 1037 1041 ** .dt %>X .dd right justify the rest of the string and pad with character "X" 1038 1042 ** .dt %|X .dd pad to the end of the line with character "X" 1043 ** .dt %*X .dd soft-fill with character "X" as pad 1039 1044 ** .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. 1040 1052 ** .pp 1041 1053 ** See also: ``$$to_chars''. … … 1353 1365 ** at the top of the next page (0 lines of context). 1354 1366 */ 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)" }, 1356 1368 /* 1357 1369 ** .pp … … 2740 2752 ** .dt %>X .dd right justify the rest of the string and pad with "X" 2741 2753 ** .dt %|X .dd pad to the end of the line with "X" 2754 ** .dt %*X .dd soft-fill with character "X" as pad 2742 2755 ** .de 2756 ** For an explanation of `soft-fill', see the ``$$index_format'' documentation. 2743 2757 ** .pp 2744 2758 ** * = can be optionally printed if nonzero -
lib.h
r5092 r5184 85 85 # define MIN(a,b) ((a) < (b) ? (a) : (b)) 86 86 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 87 94 88 95 #define FOREVER while (1) -
menu.c
r4898 r5184 161 161 int cols = COLS - shift; 162 162 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); 164 164 s[n - 1] = 0; 165 165 FREE (&scratch); -
muttlib.c
r5148 r5184 1000 1000 char prefix[SHORT_STRING], buf[LONG_STRING], *cp, *wptr = dest, ch; 1001 1001 char ifstring[SHORT_STRING], elsestring[SHORT_STRING]; 1002 char remainder[LONG_STRING]; 1002 1003 size_t wlen, count, len, wid; 1003 1004 pid_t pid; … … 1148 1149 count = 0; 1149 1150 while (count < sizeof (prefix) && 1150 (isdigit ((unsigned char) *src) || *src == '.' || *src == '-' ))1151 (isdigit ((unsigned char) *src) || *src == '.' || *src == '-' || *src == '=')) 1151 1152 { 1152 1153 *cp++ = *src++; … … 1240 1241 break; /* skip rest of input */ 1241 1242 } 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 1242 1283 else 1243 1284 { -
query.c
r5010 r5184 205 205 mutt_format_string (buf2, sizeof (buf2), 206 206 FirstColumn + 2, FirstColumn + 2, 207 0, ' ', table[num].data->name,207 FMT_LEFT, ' ', table[num].data->name, 208 208 mutt_strlen (table[num].data->name), 0); 209 209 -
recvcmd.c
r4343 r5184 183 183 { 184 184 mutt_format_string (prompt, sizeof (prompt) - 4, 185 0, COLS-extra_space, 0, 0,185 0, COLS-extra_space, FMT_LEFT, 0, 186 186 prompt, sizeof (prompt), 0); 187 187 safe_strcat (prompt, sizeof (prompt), "...?");
