<<< Date Index >>>     <<< Thread Index >>>

[PATCH] status_time: show date and time in mutt status bar



Hi all,

I've been using a patch by Byrial Jensen, which makes mutt display the
date and/or time in its status bar, for years.  Maybe not one of the
most useful, or problem-solving patches, but I just like it.

I have attached an updated version of this patch, which applies to
CVS.  I'm not arguing for its inclusion into CVS, just wanted to share
it with you.  All credits for this patch go to Byrial Jensen.

-- 
René Clerc                      - (rene@xxxxxxxx) - PGP: 0x9ACE0AC7

Cogito cogito ergo cogito sum.
-Ambrose Bierce, "The Devil's Dictionary"
? patch-1.3.23.bj.status-time.1
? stamp-h1
Index: PATCHES
===================================================================
RCS file: /home/roessler/cvs/mutt/PATCHES,v
retrieving revision 3.6
diff -u -r3.6 PATCHES
--- PATCHES     9 Dec 2002 17:44:54 -0000       3.6
+++ PATCHES     13 Apr 2005 15:21:51 -0000
@@ -0,0 +1 @@
+patch-cvs.rc.status-time.1
Index: curs_main.c
===================================================================
RCS file: /home/roessler/cvs/mutt/curs_main.c,v
retrieving revision 3.21
diff -u -r3.21 curs_main.c
--- curs_main.c 28 Feb 2005 18:33:45 -0000      3.21
+++ curs_main.c 13 Apr 2005 15:21:51 -0000
@@ -558,7 +558,7 @@
          menu_redraw_current (menu);
       }
 
-      if (menu->redraw & REDRAW_STATUS) 
+      if ((menu->redraw & REDRAW_STATUS) || update_status_time ())
       {
        menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
        CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
Index: globals.h
===================================================================
RCS file: /home/roessler/cvs/mutt/globals.h,v
retrieving revision 3.16
diff -u -r3.16 globals.h
--- globals.h   12 Feb 2005 20:08:19 -0000      3.16
+++ globals.h   13 Apr 2005 15:21:51 -0000
@@ -171,6 +171,7 @@
 WHERE short ReadInc;
 WHERE short SendmailWait;
 WHERE short SleepTime INITVAL (1);
+WHERE short StatusUpdate;
 WHERE short Timeout;
 WHERE short WrapMargin;
 WHERE short WriteInc;
Index: init.h
===================================================================
RCS file: /home/roessler/cvs/mutt/init.h,v
retrieving revision 3.70
diff -u -r3.70 init.h
--- init.h      23 Mar 2005 10:51:11 -0000      3.70
+++ init.h      13 Apr 2005 15:21:52 -0000
@@ -2585,6 +2585,9 @@
   ** .dt %u  .dd number of unread messages *
   ** .dt %v  .dd Mutt version string
   ** .dt %V  .dd currently active limit pattern, if any *
+  ** .dt %[fmt] .dd the current date and time. ``fmt'' is
+  **                expanded by the system call ``strftime'';
+  **                a leading bang disables locales 
   ** .dt %>X .dd right justify the rest of the string and pad with "X"
   ** .dt %|X .dd pad to the end of the line with "X"
   ** .de
@@ -2630,6 +2633,16 @@
   ** Setting this variable causes the ``status bar'' to be displayed on
   ** the first line of the screen rather than near the bottom.
   */
+  { "status_update",  DT_NUM, R_NONE, UL &StatusUpdate, -1 },
+  /*
+   ** .pp
+   ** This variable controls, if positive, the maximum interval in seconds
+   ** before the time in the status line is updated. It is checked at
+   ** every key press and after a keyboard $$timeout.
+   ** If the value is zero, the status line will be updated at every check.
+   ** If it is negative, the status time will only be updated
+   ** if it necessary to update to the status line for some other reason.
+   */
   { "strict_threads",  DT_BOOL, R_RESORT|R_RESORT_INIT|R_INDEX, 
OPTSTRICTTHREADS, 0 },
   /*
   ** .pp
Index: menu.c
===================================================================
RCS file: /home/roessler/cvs/mutt/menu.c,v
retrieving revision 3.16
diff -u -r3.16 menu.c
--- menu.c      28 Feb 2005 15:15:23 -0000      3.16
+++ menu.c      13 Apr 2005 15:21:53 -0000
@@ -1078,3 +1078,23 @@
   }
   /* not reached */
 }
+
+int update_status_time ()
+{
+  static time_t Last;
+  time_t now;
+
+  if (StatusUpdate < 0)
+    return 0;
+  else if (StatusUpdate == 0)
+    return 1;
+
+  now = time (NULL);
+  if (now - Last >= StatusUpdate)
+  {
+    Last = now;
+    return 1;
+  }
+  else
+    return 0;
+}
Index: mutt_menu.h
===================================================================
RCS file: /home/roessler/cvs/mutt/mutt_menu.h,v
retrieving revision 3.2
diff -u -r3.2 mutt_menu.h
--- mutt_menu.h 4 Oct 2003 20:34:59 -0000       3.2
+++ mutt_menu.h 13 Apr 2005 15:21:53 -0000
@@ -108,3 +108,5 @@
 /* used in both the index and pager index to make an entry. */
 void index_make_entry (char *, size_t, struct menu_t *, int);
 int index_color (int);
+
+int update_status_time (void);
Index: pager.c
===================================================================
RCS file: /home/roessler/cvs/mutt/pager.c,v
retrieving revision 3.18
diff -u -r3.18 pager.c
--- pager.c     12 Feb 2005 19:28:26 -0000      3.18
+++ pager.c     13 Apr 2005 15:21:53 -0000
@@ -1733,7 +1733,7 @@
       SETCOLOR (MT_COLOR_NORMAL);
     }
 
-    if ((redraw & REDRAW_INDEX) && index)
+    if (index && ((redraw & REDRAW_INDEX) || update_status_time ()))
     {
       /* redraw the pager_index indicator, because the
        * flags for this message might have changed. */
Index: status.c
===================================================================
RCS file: /home/roessler/cvs/mutt/status.c,v
retrieving revision 3.6
diff -u -r3.6 status.c
--- status.c    3 Feb 2005 17:01:44 -0000       3.6
+++ status.c    13 Apr 2005 15:21:53 -0000
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <unistd.h>
+#include <locale.h>
 
 static char *get_sort_str (char *buf, size_t buflen, int method)
 {
@@ -280,6 +281,61 @@
       *buf = 0;
       return (src);
 
+    case '[':
+      {
+       int do_locales;
+       int len = sizeof (fmt) - 1;
+
+       cp = fmt;
+       if (*src == '!')
+       {
+         do_locales = 0;
+         src++;
+       }
+       else
+         do_locales = 1;
+
+       while (len > 0 && *src != ']')
+       {
+         if (*src == '%')
+         {
+           src++;
+           if (len >= 2)
+           {
+             *cp++ = '%';
+             *cp++ = *src;
+             len -= 2;
+           }
+           else
+             break; /* not enough space */
+           src++;
+         }
+         else
+         {
+           *cp++ = *src++;
+            len--;
+         }
+       }
+       *cp = 0;
+       src++;
+
+       if (do_locales && Locale)
+         setlocale (LC_TIME, Locale);
+
+       {
+         time_t now = time (NULL);
+
+         strftime (tmp, sizeof (tmp), fmt, localtime (&now));
+       }
+
+       if (do_locales && Locale)
+         setlocale (LC_TIME, "C");
+
+       snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
+       snprintf (buf, buflen, fmt, tmp);
+      }
+      break;
+
     default:
       snprintf (buf, buflen, "%%%s%c", prefix, op);
       break;

Attachment: pgpUoM6N1Lwz0.pgp
Description: PGP signature