From be684ef23cd68926f7ca33a0b09591f970287407 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Fri, 28 Jun 2019 15:09:51 -0700 Subject: [PATCH] Add size display configuration variables. Although it would be nice to "open this up" more, performance and security/stability issues would arise. Based on the thread in mutt-dev, I hope these vars will satisfy most customization needs: $size_show_bytes $size_show_mb $size_show_fractions $size_units_on_left --- doc/manual.xml.head | 46 +++++++++++++++++++++++++++++++++++++++++++++ init.h | 37 ++++++++++++++++++++++++++++++------ mutt.h | 4 ++++ muttlib.c | 38 ++++++++++++++++++++++++------------- 4 files changed, 106 insertions(+), 19 deletions(-) diff --git a/doc/manual.xml.head b/doc/manual.xml.head index 8695c590..e1953e3c 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -5132,6 +5132,52 @@ set index_format="%4C %Z %{%b %d} %-15.15L (%?l?%4l&%4c?)%* %s" + +Bytes size display + + +Various format strings contain expandos that display the size of +messages in bytes. This includes +%s in $attach_format, +%l in $compose_format, +%s in $folder_format, +%c in $index_format, +and %l and %L in $status_format. +There are four configuration variables that can be used to customize +how the numbers are displayed. + + + + $size_show_bytes + will display the number of bytes when the size is < 1 + kilobyte. When unset, kilobytes will be displayed instead. + + + + $size_show_mb will display the + number of megabytes when the size is >= 1 megabyte. When + unset, kilobytes will be displayed instead (which could be a large + number). + + + + $size_show_fractions, + will display numbers with a single decimal place for values from + 0 to 10 kilobytes, and 1 to 10 megabytes. + + + + $size_units_on_left will + display the unit (K or M to the left + of the number, instead of the right if unset. + + + + These variables also affect size display in a few other places, such + as progress indicators and attachment delimeters in the pager. + + + diff --git a/init.h b/init.h index ea72a214..e24d7bcd 100644 --- a/init.h +++ b/init.h @@ -253,7 +253,7 @@ struct option_t MuttVars[] = { ** .dt %M .dd MIME subtype ** .dt %n .dd attachment number ** .dt %Q .dd ``Q'', if MIME part qualifies for attachment counting - ** .dt %s .dd size + ** .dt %s .dd size (see $formatstrings-size) ** .dt %t .dd tagged flag ** .dt %T .dd graphic tree characters ** .dt %u .dd unlink (=to delete) flag @@ -505,7 +505,7 @@ struct option_t MuttVars[] = { ** .dl ** .dt %a .dd total number of attachments ** .dt %h .dd local hostname - ** .dt %l .dd approximate size (in bytes) of the current message + ** .dt %l .dd approximate size (in bytes) of the current message (see $formatstrings-size) ** .dt %v .dd Mutt version string ** .de ** .pp @@ -1020,7 +1020,7 @@ struct option_t MuttVars[] = { ** .dt %m .dd number of messages in the mailbox * ** .dt %n .dd number of unread messages in the mailbox * ** .dt %N .dd N if mailbox has new mail, blank otherwise - ** .dt %s .dd size in bytes + ** .dt %s .dd size in bytes (see $formatstrings-size) ** .dt %t .dd ``*'' if the file is tagged, blank otherwise ** .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'' @@ -1626,7 +1626,7 @@ struct option_t MuttVars[] = { ** .dt %A .dd reply-to address (if present; otherwise: address of author) ** .dt %b .dd filename of the original message folder (think mailbox) ** .dt %B .dd the list to which the letter was sent, or else the folder name (%b). - ** .dt %c .dd number of characters (bytes) in the message + ** .dt %c .dd number of characters (bytes) in the message (see $formatstrings-size) ** .dt %C .dd current message number ** .dt %d .dd date and time of the message in the format specified by ** $$date_format converted to sender's time zone @@ -3315,6 +3315,31 @@ struct option_t MuttVars[] = { ** replacing ``%s'' with the supplied string. ** For the default value, ``joe'' would be expanded to: ``~f joe | ~s joe''. */ + { "size_show_bytes", DT_BOOL, R_MENU, {.l=OPTSIZESHOWBYTES}, {.l=0} }, + /* + ** .pp + ** If \fIset\fP, message sizes will display bytes for values less than + ** 1 kilobyte. See $formatstrings-size. + */ + { "size_show_fractions", DT_BOOL, R_MENU, {.l=OPTSIZESHOWFRACTIONS}, {.l=1} }, + /* + ** .pp + ** If \fIset\fP, message sizes will be displayed with a single decimal value + ** for sizes from 0 to 10 kilobytes and 1 to 10 megabytes. + ** See $formatstrings-size. + */ + { "size_show_mb", DT_BOOL, R_MENU, {.l=OPTSIZESHOWMB}, {.l=1} }, + /* + ** .pp + ** If \fIset\fP, message sizes will display megabytes for values greater than + ** or equal to 1 megabyte. See $formatstrings-size. + */ + { "size_units_on_left", DT_BOOL, R_MENU, {.l=OPTSIZEUNITSONLEFT}, {.l=0} }, + /* + ** .pp + ** If \fIset\fP, message sizes units will be displayed to the left of the number. + ** See $formatstrings-size. + */ { "sleep_time", DT_NUM, R_NONE, {.p=&SleepTime}, {.l=1} }, /* ** .pp @@ -3896,9 +3921,9 @@ struct option_t MuttVars[] = { ** .dt %f .dd the full pathname of the current mailbox ** .dt %F .dd number of flagged messages * ** .dt %h .dd local hostname - ** .dt %l .dd size (in bytes) of the current mailbox * + ** .dt %l .dd size (in bytes) of the current mailbox (see $formatstrings-size) * ** .dt %L .dd size (in bytes) of the messages shown - ** (i.e., which match the current limit) * + ** (i.e., which match the current limit) (see $formatstrings-size) * ** .dt %m .dd the number of messages in the mailbox * ** .dt %M .dd the number of messages shown (i.e., which match the current limit) * ** .dt %n .dd number of new messages in the mailbox * diff --git a/mutt.h b/mutt.h index f36edb2f..ff257127 100644 --- a/mutt.h +++ b/mutt.h @@ -514,6 +514,10 @@ enum #endif OPTSIGDASHES, OPTSIGONTOP, + OPTSIZESHOWBYTES, + OPTSIZESHOWMB, + OPTSIZESHOWFRACTIONS, + OPTSIZEUNITSONLEFT, OPTSORTRE, OPTSPAMSEP, OPTSTATUSONTOP, diff --git a/muttlib.c b/muttlib.c index ba8f9970..9a758b01 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1027,25 +1027,37 @@ void mutt_pretty_mailbox (char *s, size_t buflen) void mutt_pretty_size (char *s, size_t len, LOFF_T n) { - if (n == 0) - strfcpy (s, "0K", len); - /* Change in format released in 1.10.0, but reverted after feedback: - * if (n < 1000) - * snprintf (s, len, "%d", (int)n); - */ - else if (n < 10189) /* 0.1K - 9.9K */ - snprintf (s, len, "%3.1fK", (n < 103) ? 0.1 : n / 1024.0); - else if (n < 1023949) /* 10K - 999K */ + if (option (OPTSIZESHOWBYTES) && (n < 1024)) + snprintf (s, len, "%d", (int)n); + else if (n == 0) + strfcpy (s, + option (OPTSIZEUNITSONLEFT) ? "K0" : "0K", + len); + else if (option (OPTSIZESHOWFRACTIONS) && (n < 10189)) /* 0.1K - 9.9K */ + { + snprintf (s, len, + option (OPTSIZEUNITSONLEFT) ? "K%3.1f" : "%3.1fK", + (n < 103) ? 0.1 : n / 1024.0); + } + else if (!option (OPTSIZESHOWMB) || (n < 1023949)) /* 10K - 999K */ { /* 51 is magic which causes 10189/10240 to be rounded up to 10 */ - snprintf (s, len, OFF_T_FMT "K", (n + 51) / 1024); + snprintf (s, len, + option (OPTSIZEUNITSONLEFT) ? ("K" OFF_T_FMT) : (OFF_T_FMT "K"), + (n + 51) / 1024); + } + else if (option (OPTSIZESHOWFRACTIONS) && (n < 10433332)) /* 1.0M - 9.9M */ + { + snprintf (s, len, + option (OPTSIZEUNITSONLEFT) ? "M%3.1f" : "%3.1fM", + n / 1048576.0); } - else if (n < 10433332) /* 1.0M - 9.9M */ - snprintf (s, len, "%3.1fM", n / 1048576.0); else /* 10M+ */ { /* (10433332 + 52428) / 1048576 = 10 */ - snprintf (s, len, OFF_T_FMT "M", (n + 52428) / 1048576); + snprintf (s, len, + option (OPTSIZEUNITSONLEFT) ? ("M" OFF_T_FMT) : (OFF_T_FMT "M"), + (n + 52428) / 1048576); } } -- 2.40.0