]> granicus.if.org Git - mutt/commitdiff
Add size display configuration variables.
authorKevin McCarthy <kevin@8t8.us>
Fri, 28 Jun 2019 22:09:51 +0000 (15:09 -0700)
committerKevin McCarthy <kevin@8t8.us>
Sat, 17 Aug 2019 20:55:44 +0000 (13:55 -0700)
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
init.h
mutt.h
muttlib.c

index 8695c59019569c654ce1053588529644aa3a1aba..e1953e3cff7454b10e2d8273719e047964e800f3 100644 (file)
@@ -5132,6 +5132,52 @@ set index_format="%4C %Z %{%b %d} %-15.15L (%?l?%4l&amp;%4c?)%*  %s"</screen>
 
 </sect2>
 
+<sect2 id="formatstrings-size">
+<title>Bytes size display</title>
+
+<para>
+Various format strings contain expandos that display the size of
+messages in bytes.  This includes
+<literal>%s</literal> in <link linkend="attach-format">$attach_format</link>,
+<literal>%l</literal> in <link linkend="compose-format">$compose_format</link>,
+<literal>%s</literal> in <link linkend="folder-format">$folder_format</link>,
+<literal>%c</literal> in <link linkend="index-format">$index_format</link>,
+and %l and %L in <link linkend="status-format">$status_format</link>.
+There are four configuration variables that can be used to customize
+how the numbers are displayed.
+</para>
+
+<para>
+  <link linkend="size-show-bytes">$size_show_bytes</link>
+  will display the number of bytes when the size is &lt; 1
+  kilobyte.  When unset, kilobytes will be displayed instead.
+</para>
+
+<para>
+  <link linkend="size-show-mb">$size_show_mb</link> will display the
+  number of megabytes when the size is &gt;= 1 megabyte.  When
+  unset, kilobytes will be displayed instead (which could be a large
+  number).
+</para>
+
+<para>
+  <link linkend="size-show-fractions">$size_show_fractions</link>,
+  will display numbers with a single decimal place for values from
+  0 to 10 kilobytes, and 1 to 10 megabytes.
+</para>
+
+<para>
+  <link linkend="size-units-on-left">$size_units_on_left</link> will
+  display the unit (<quote>K</quote> or <quote>M</quote> to the left
+  of the number, instead of the right if unset.
+</para>
+
+<para>
+  These variables also affect size display in a few other places, such
+  as progress indicators and attachment delimeters in the pager.
+</para>
+</sect2>
+
 </sect1>
 
 <sect1 id="mailto-allow">
diff --git a/init.h b/init.h
index ea72a214ae4e3c9f59ea20c9968d1324ad05b11a..e24d7bcddd4962d564c9fb331ba7178307fb95d6 100644 (file)
--- 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 f36edb2fbeabe53cac005259e8b56dcdb0891ffe..ff257127fe7ca4563ef671a4b4ff84e057f2416d 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -514,6 +514,10 @@ enum
 #endif
   OPTSIGDASHES,
   OPTSIGONTOP,
+  OPTSIZESHOWBYTES,
+  OPTSIZESHOWMB,
+  OPTSIZESHOWFRACTIONS,
+  OPTSIZEUNITSONLEFT,
   OPTSORTRE,
   OPTSPAMSEP,
   OPTSTATUSONTOP,
index ba8f99701a648583d78f1a15d8e4c40050048ec8..9a758b01cfaa0180cc0455d2e402081ffe623269 100644 (file)
--- 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);
   }
 }