rework m_strformat so that it takes the cols number to use in case of
[apps/madmutt.git] / muttlib.c
index f63ad45..946a2f5 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -29,8 +29,6 @@
 
 #include <lib-crypt/crypt.h>
 
-#define SW              (option(OPTMBOXPANE)?SidebarWidth:0)
-
 /* Modified by blong to accept a "suggestion" for file name.  If
  * that file exists, then construct one with unique name but 
  * keep any extension.  This might fail, I guess.
@@ -328,14 +326,14 @@ void mutt_safe_path(char *s, ssize_t l, address_t *a)
     }
 }
 
-ssize_t m_strformat(char *dst, ssize_t dlen, const char *fmt,
+ssize_t m_strformat(char *dst, ssize_t dlen, int width, const char *fmt,
                     format_t *callback, anytype cdata, format_flag flags)
 {
     ssize_t pos = flags & M_FORMAT_ARROWCURSOR ? 3 : 0;
 
     m_strpad(dst, dlen, '\0', pos + 1);
     if (!fmt)
-        return;
+        return pos;
 
     while (*fmt) {
         int ch;
@@ -392,25 +390,24 @@ ssize_t m_strformat(char *dst, ssize_t dlen, const char *fmt,
             }
 
             switch (ch) {
-                ssize_t col;
                 char lower, nodots, buf[LONG_STRING];
 
               case '>':                 /* right justify to EOL */
-                col = mutt_strwidth(dst);
+                width -= mutt_strwidth(dst);
 
                 ch = *fmt++;            /* pad char */
 
-                if (COLS - SW > col) {
-                    m_strformat(buf, sizeof(buf), fmt, callback, cdata, flags);
-                    pos += m_strpad(dst + pos, dlen - pos, ch,
-                                    COLS - SW - col - mutt_strwidth(buf));
+                if (width > 0) {
+                    m_strformat(buf, sizeof(buf), 0, fmt, callback, cdata, flags);
+                    width -= mutt_strwidth(buf);
+                    pos += m_strpad(dst + pos, dlen - pos, ch, width);
                     pos += m_strcpy(dst + pos, dlen - pos, buf);
                 }
                 return pos;             /* skip rest of input */
 
               case '|':                 /* pad to EOL */
-                return pos + m_strpad(dst + pos, dlen - pos, *fmt,
-                                      COLS - SW - mutt_strwidth(dst));
+                width -= mutt_strwidth(dst);
+                return pos + m_strpad(dst + pos, dlen - pos, *fmt, width);
 
               default:
                 lower = nodots = 0;