]> granicus.if.org Git - neomutt/commitdiff
Add size display configuration variables
authorKevin McCarthy <kevin@8t8.us>
Fri, 28 Jun 2019 22:09:51 +0000 (15:09 -0700)
committerRichard Russon <rich@flatcap.org>
Mon, 19 Aug 2019 22:03:24 +0000 (23:03 +0100)
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

Co-authored-by: Richard Russon <rich@flatcap.org>
doc/manual.xml.head
globals.h
init.h
mutt/string.c
mutt/string2.h
muttlib.c
muttlib.h
progress.c

index c3a93376c2f83fe9023171c14c5411f72cf7be7d..8d765b7b5e67258fc8bd40cfb5ce659208f8e269 100644 (file)
@@ -6997,6 +6997,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">
index d3ab4a7ac4d4464ae422e39e9efc08126836ba11..f53885be4eadc63b84488790ab7be0368e52d8df 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -250,6 +250,10 @@ WHERE bool C_Score;                          ///< Config: Use message scoring
 WHERE bool C_SidebarVisible;                 ///< Config: (sidebar) Show the sidebar
 WHERE bool C_SidebarOnRight;                 ///< Config: (sidebar) Display the sidebar on the right
 #endif
+WHERE bool C_SizeShowBytes;                  ///< Config: Show smaller sizes in bytes
+WHERE bool C_SizeShowFractions;              ///< Config: Show size fractions with a single decimal place
+WHERE bool C_SizeShowMb;                     ///< Config: Show sizes in megabytes for sizes greater than 1 megabyte
+WHERE bool C_SizeUnitsOnLeft;                ///< Config: Show the units as a prefix to the size
 WHERE bool C_StatusOnTop;                    ///< Config: Display the status bar at the top
 WHERE bool C_Suspend;                        ///< Config: Allow the user to suspend NeoMutt using '^Z'
 WHERE bool C_TextFlowed;                     ///< Config: Generate 'format=flowed' messages
diff --git a/init.h b/init.h
index 27bf92e89264b6b3a03476a20179ed5ca06c3fb3..bd93d684ddaf6e801314ffb70334caf2d348a3b5 100644 (file)
--- a/init.h
+++ b/init.h
@@ -314,7 +314,7 @@ struct ConfigDef 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 Graphic tree characters
   ** .dt %t  .dd Tagged flag
   ** .dt %u  .dd Unlink (=to delete) flag
@@ -554,7 +554,7 @@ struct ConfigDef 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 NeoMutt version string
   ** .de
   ** .pp
@@ -1154,7 +1154,7 @@ struct ConfigDef 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"
@@ -1816,7 +1816,7 @@ struct ConfigDef MuttVars[] = {
   ** .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 Current message number
-  ** .dt %c .dd Number of characters (bytes) in the message
+  ** .dt %c .dd Number of characters (bytes) in the message (see $formatstrings-size)
   ** .dt %D .dd Date and time of message using $date_format and local timezone
   ** .dt %d .dd Date and time of message using $date_format and sender's timezone
   ** .dt %e .dd Current message number in thread
@@ -3814,6 +3814,31 @@ struct ConfigDef 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, &C_SizeShowBytes, false },
+  /*
+  ** .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, &C_SizeShowFractions, true },
+  /*
+  ** .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, &C_SizeShowMb, true },
+  /*
+  ** .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, &C_SizeUnitsOnLeft, false },
+  /*
+  ** .pp
+  ** If \fIset\fP, message sizes units will be displayed to the left of the number.
+  ** See $formatstrings-size.
+  */
   { "skip_quoted_offset", DT_NUMBER|DT_NOT_NEGATIVE, &C_SkipQuotedOffset, 0 },
   /*
   ** .pp
@@ -4417,9 +4442,9 @@ struct ConfigDef 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 *
index ebd1046cb82a043fe4bcf9b06d86d1630e3ae131..4a582d7c351a3c183f7f96518fa5a137fceb86c6 100644 (file)
@@ -1038,41 +1038,6 @@ const char *mutt_str_find_word(const char *src)
   return src;
 }
 
-/**
- * mutt_str_pretty_size - Display an abbreviated size, like 3.4K
- * @param buf    Buffer for the result
- * @param buflen Length of the buffer
- * @param num    Number to abbreviate
- */
-void mutt_str_pretty_size(char *buf, size_t buflen, size_t num)
-{
-  if (!buf || (buflen == 0))
-    return;
-
-  if (num < 1000)
-  {
-    snprintf(buf, buflen, "%dB", (int) num);
-  }
-  else if (num < 10189) /* 0.1K - 9.9K */
-  {
-    snprintf(buf, buflen, "%3.1fK", num / 1024.0);
-  }
-  else if (num < 1023949) /* 10K - 999K */
-  {
-    /* 51 is magic which causes 10189/10240 to be rounded up to 10 */
-    snprintf(buf, buflen, "%zuK", (num + 51) / 1024);
-  }
-  else if (num < 10433332) /* 1.0M - 9.9M */
-  {
-    snprintf(buf, buflen, "%3.1fM", num / 1048576.0);
-  }
-  else /* 10M+ */
-  {
-    /* (10433332 + 52428) / 1048576 = 10 */
-    snprintf(buf, buflen, "%zuM", (num + 52428) / 1048576);
-  }
-}
-
 /**
  * mutt_str_getenv - Get an environment variable
  * @param name Environment variable to get
index f70012a43af186049aaf040ec2a326b14f7da30d..19249f026c7dc91bd0e558abb0a754b98c8c1b09 100644 (file)
@@ -86,7 +86,6 @@ bool        mutt_str_is_email_wsp(char c);
 size_t      mutt_str_lws_len(const char *s, size_t n);
 size_t      mutt_str_lws_rlen(const char *s, size_t n);
 const char *mutt_str_next_word(const char *s);
-void        mutt_str_pretty_size(char *buf, size_t buflen, size_t num);
 int         mutt_str_remall_strcasestr(char *str, const char *target);
 void        mutt_str_remove_trailing_ws(char *s);
 void        mutt_str_replace(char **p, const char *s);
index 390342aae65e488def4949a69e92e518e01b60ce..a6bea70540cff1b016fcc8b3911a44ef08c35cc1 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -1710,3 +1710,43 @@ void mutt_buffer_sanitize_filename(struct Buffer *buf, const char *path, short s
       mutt_buffer_addch(buf, *path);
   }
 }
+
+/**
+ * mutt_str_pretty_size - Display an abbreviated size, like 3.4K
+ * @param buf    Buffer for the result
+ * @param buflen Length of the buffer
+ * @param num    Number to abbreviate
+ */
+void mutt_str_pretty_size(char *buf, size_t buflen, size_t num)
+{
+  if (!buf || (buflen == 0))
+    return;
+
+  if (C_SizeShowBytes && (num < 1024))
+  {
+    snprintf(buf, buflen, "%d", (int) num);
+  }
+  else if (num == 0)
+  {
+    mutt_str_strfcpy(buf, C_SizeUnitsOnLeft ? "K0" : "0K", buflen);
+  }
+  else if (C_SizeShowFractions && (num < 10189)) /* 0.1K - 9.9K */
+  {
+    snprintf(buf, buflen, C_SizeUnitsOnLeft ? "K%3.1f" : "%3.1fK",
+             (num < 103) ? 0.1 : (num / 1024.0));
+  }
+  else if (!C_SizeShowMb || (num < 1023949)) /* 10K - 999K */
+  {
+    /* 51 is magic which causes 10189/10240 to be rounded up to 10 */
+    snprintf(buf, buflen, C_SizeUnitsOnLeft ? ("K%zu") : ("%zuK"), (num + 51) / 1024);
+  }
+  else if (C_SizeShowFractions && (num < 10433332)) /* 1.0M - 9.9M */
+  {
+    snprintf(buf, buflen, C_SizeUnitsOnLeft ? "M%3.1f" : "%3.1fM", num / 1048576.0);
+  }
+  else /* 10M+ */
+  {
+    /* (10433332 + 52428) / 1048576 = 10 */
+    snprintf(buf, buflen, C_SizeUnitsOnLeft ? ("M%zu") : ("%zuM"), (num + 52428) / 1048576);
+  }
+}
index 24bec738ccf6c8f71220e3b827ae4976b9be8738..a60530f5afd4a2d221668f9daadeb9b7f4c922e0 100644 (file)
--- a/muttlib.h
+++ b/muttlib.h
@@ -71,6 +71,7 @@ void        mutt_safe_path(char *s, size_t l, const struct Address *a);
 int         mutt_save_confirm(const char *s, struct stat *st);
 void        mutt_save_path(char *d, size_t dsize, const struct Address *a);
 void        mutt_sleep(short s);
+void        mutt_str_pretty_size(char *buf, size_t buflen, size_t num);
 
 #define mutt_mktemp(buf, buflen)                         mutt_mktemp_pfx_sfx(buf, buflen, "neomutt", NULL)
 #define mutt_mktemp_pfx_sfx(buf, buflen, prefix, suffix) mutt_mktemp_full(buf, buflen, prefix, suffix, __FILE__, __LINE__)
index d8f0e99329f85bcff41e843bd18186e2825c4ce6..5563769ca509e4fd3bab040dc47e491cab94456b 100644 (file)
@@ -37,6 +37,7 @@
 #include "curs_lib.h"
 #include "mutt_curses.h"
 #include "mutt_logging.h"
+#include "muttlib.h"
 #include "options.h"
 
 /* These Config Variables are only used in progress.c */