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

Re: xtitles (was: patches from the debian package)



 On Tuesday, November 4, 2003 at 9:22:59 PM +0100, Alain Bench wrote:

> [xtitles] Nice feature, but lacks refresh in pager mode.

    The attached new xtitles patch fixes this. It applies cleanly to
Mutt 1.5.5.1 (and to older versions with fuzz 2).


Bye!    Alain.
-- 
<URL:http://www.tuxedo.org/~esr/faqs/smart-questions.html>
Patch nt.xtitles.3.ab
Patch based on mostly identical serie having controversed origin:

  patch-0.17.9.ab.xtitles.1
  patch-1.2(.nt).xtitles.1              Neil Townsend
  patch-1.3.27.bse.xtitles.1
  patch-1.5.1-ow.xtitles.2              Omen Wild
  patch-1.5.3.sjd.xtitles-1.2.merge     Simon Dassow

Modified to support PuTTY and Cygwin terminals. AB.
Modified to refresh title bar in pager mode. AB.


diff -prud mutt-1.5.5.1.orig/curs_main.c mutt-1.5.5.1/curs_main.c
--- mutt-1.5.5.1.orig/curs_main.c       Wed Nov  5 10:41:31 2003
+++ mutt-1.5.5.1/curs_main.c    Mon Dec  1 10:13:51 2003
@@ -103,6 +103,19 @@ static const char *No_visible = N_("No v
 extern const char *ReleaseDate;
 extern size_t UngetCount;
 
+#define ASCII_CTRL_G                  0x07
+#define ASCII_CTRL_OPEN_SQUARE_BRAKET 0x1b
+ 
+void set_xterm_title_bar(char *title)
+{
+  fprintf(stderr ,"%c]2;%s%c", ASCII_CTRL_OPEN_SQUARE_BRAKET, title, 
ASCII_CTRL_G);
+}
+
+void set_xterm_icon_name(char *name)
+{
+  fprintf(stderr, "%c]1;%s%c", ASCII_CTRL_OPEN_SQUARE_BRAKET, name, 
ASCII_CTRL_G);
+}
+
 void index_make_entry (char *s, size_t l, MUTTMENU *menu, int num)
 {
   format_flag flag = M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | 
M_FORMAT_INDEX;
@@ -562,6 +575,13 @@ int mutt_index_menu (void)
        mutt_paddstr (COLS, buf);
        SETCOLOR (MT_COLOR_NORMAL);
        menu->redraw &= ~REDRAW_STATUS;
+       if (option(OPTXTERMSETTITLES))
+       {
+         menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
+         set_xterm_title_bar(buf);
+         menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
+         set_xterm_icon_name(buf);
+       }
       }
 
       menu->redraw = 0;
diff -prud mutt-1.5.5.1.orig/globals.h mutt-1.5.5.1/globals.h
--- mutt-1.5.5.1.orig/globals.h Wed Nov  5 10:41:31 2003
+++ mutt-1.5.5.1/globals.h      Mon Dec  1 10:13:51 2003
@@ -112,6 +112,8 @@ WHERE char *Tempdir;
 WHERE char *Tochars;
 WHERE char *Username;
 WHERE char *Visual;
+WHERE char *XtermTitle;
+WHERE char *XtermIcon;
 
 WHERE char *LastFolder;
 
diff -prud mutt-1.5.5.1.orig/init.c mutt-1.5.5.1/init.c
--- mutt-1.5.5.1.orig/init.c    Wed Nov  5 10:41:31 2003
+++ mutt-1.5.5.1/init.c Mon Dec  1 10:13:51 2003
@@ -891,6 +891,25 @@ static int parse_set (BUFFER *tmp, BUFFE
        toggle_option (MuttVars[idx].data);
       else
        set_option (MuttVars[idx].data);
+
+      /* sanity check for xterm */
+      if ((mutt_strcmp (MuttVars[idx].option, "xterm_set_titles") == 0)
+               && option (OPTXTERMSETTITLES))
+      {
+       char *ep = getenv ("TERM");
+       /* Make sure that the terminal can take the control codes */
+       if (ep == NULL) unset_option (MuttVars[idx].data);
+       else if (mutt_strncasecmp (ep, "xterm", 5) &&
+                mutt_strncasecmp (ep, "color-xterm", 11) &&
+                mutt_strncasecmp (ep, "eterm", 5) &&
+                mutt_strncasecmp (ep, "kterm", 5) &&
+                mutt_strncasecmp (ep, "nxterm", 6) &&
+                mutt_strncasecmp (ep, "putty", 5) &&
+                mutt_strncasecmp (ep, "cygwin", 6) &&
+                mutt_strncasecmp (ep, "rxvt", 4) )
+         unset_option (MuttVars[idx].  data);
+
+      }
     }
     else if (DTYPE (MuttVars[idx].type) == DT_STR ||
             DTYPE (MuttVars[idx].type) == DT_PATH ||
diff -prud mutt-1.5.5.1.orig/init.h mutt-1.5.5.1/init.h
--- mutt-1.5.5.1.orig/init.h    Wed Nov  5 10:41:32 2003
+++ mutt-1.5.5.1/init.h Mon Dec  1 10:13:51 2003
@@ -2669,6 +2669,27 @@ struct option_t MuttVars[] = {
   ** Controls whether mutt writes out the Bcc header when preparing
   ** messages to be sent.  Exim users may wish to use this.
   */
+  {"xterm_icon",       DT_STR,   R_BOTH, UL &XtermIcon,  UL "M%?n?AIL&ail?"},
+  /*
+  ** .pp
+  ** Controls the format of the icon title, as long as xterm_set_titles
+  ** is enabled. This string is identical in formatting to the one used by
+  ** ``$$status_format''.
+  */
+  {"xterm_set_titles", DT_BOOL,  R_BOTH, OPTXTERMSETTITLES, 0},
+  /*
+  ** .pp
+  ** Controls whether mutt sets the xterm title bar and icon name
+  ** (as long as you're in an appropriate terminal). The default must
+  ** be off to force in the validity checking.
+  */
+  {"xterm_title",      DT_STR,   R_BOTH, UL &XtermTitle, UL "Mutt with %?m?%m 
messages&no messages?%?n? [%n NEW]?"},
+  /*
+  ** .pp
+  ** Controls the format of the title bar of the xterm provided that
+  ** xterm_set_titles has been set. This string is identical in formatting
+  ** to the one used by ``$$status_format''.
+  */
   /*--*/
   { NULL }
 };
diff -prud mutt-1.5.5.1.orig/mutt.h mutt-1.5.5.1/mutt.h
--- mutt-1.5.5.1.orig/mutt.h    Wed Nov  5 10:41:32 2003
+++ mutt-1.5.5.1/mutt.h Mon Dec  1 10:13:51 2003
@@ -424,6 +424,7 @@ enum
   OPTWRAPSEARCH,
   OPTWRITEBCC,         /* write out a bcc header? */
   OPTXMAILER,
+  OPTXTERMSETTITLES,
 
   /* PGP options */
   
diff -prud mutt-1.5.5.1.orig/pager.c mutt-1.5.5.1/pager.c
--- mutt-1.5.5.1.orig/pager.c   Wed Nov  5 10:41:32 2003
+++ mutt-1.5.5.1/pager.c        Mon Dec  1 10:22:43 2003
@@ -26,6 +26,8 @@
 #include "pager.h"
 #include "attach.h"
 #include "mbyte.h"
+void set_xterm_title_bar(char *title);
+void set_xterm_icon_name(char *name);
 
 #include "mx.h"
 
@@ -1740,6 +1742,13 @@ mutt_pager (const char *banner, const ch
       SETCOLOR (MT_COLOR_STATUS);
       mutt_paddstr (COLS, buffer);
       SETCOLOR (MT_COLOR_NORMAL);
+      if (option(OPTXTERMSETTITLES))
+      {
+       menu_status_line (buffer, sizeof (buffer), index, NONULL (XtermTitle));
+       set_xterm_title_bar(buffer);
+       menu_status_line (buffer, sizeof (buffer), index, NONULL (XtermIcon));
+       set_xterm_icon_name(buffer);
+      }
     }
 
     redraw = 0;
--- PATCHES     Tue Nov  6 19:59:33 2001
+++ PATCHES     Tue Nov  6 19:59:42 2001
@@ -1,0 +1 @@
+patch-1.5.5.1.nt.xtitles.3.ab