Skip to content

Instantly share code, notes, and snippets.

@simmel
Last active December 19, 2015 02:29
Show Gist options
  • Save simmel/5883831 to your computer and use it in GitHub Desktop.
Save simmel/5883831 to your computer and use it in GitHub Desktop.
# vi: ft=diff
This is the xterm title patch as found on the mutt mailing lists.
* Changes made:
- 2013-06-20 simmel: fixup to apply to 1.5.21.
- 2007-01-27 myon: using %P caused a segfault, updated status.c to catch
menu==NULL.
- 2007-02-20 myon: make the note about the xterm_set_titles defaults a
comment.
== END PATCH
Index: mutt/PATCHES
===================================================================
--- mutt/PATCHES.orig 2007-02-20 16:46:09.943601256 +0100
+++ mutt/PATCHES 2007-02-20 16:46:09.943601256 +0100
@@ -0,0 +1 @@
+patch-1.5.13.nt+ab.xtitles.4
Index: mutt/curs_main.c
===================================================================
--- mutt.orig/curs_main.c 2006-12-12 14:15:02.000000000 +0100
+++ mutt/curs_main.c 2007-02-20 16:53:27.211126488 +0100
@@ -110,6 +110,19 @@ static const char *No_visible = N_("No v
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;
@@ -568,6 +581,13 @@ int mutt_index_menu (void)
SETCOLOR (MT_COLOR_NORMAL);
BKGDSET (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;
Index: mutt/globals.h
===================================================================
--- mutt.orig/globals.h 2007-01-04 15:23:49.000000000 +0100
+++ mutt/globals.h 2007-01-27 19:33:32.000000000 +0100
@@ -137,6 +137,8 @@ WHERE char *Tempdir;
WHERE char *Tochars;
WHERE char *Username;
WHERE char *Visual;
+WHERE char *XtermTitle;
+WHERE char *XtermIcon;
WHERE char *CurrentFolder;
WHERE char *LastFolder;
Index: mutt/init.c
===================================================================
--- mutt.orig/init.c 2006-12-12 14:15:03.000000000 +0100
+++ mutt/init.c 2007-01-27 19:33:32.000000000 +0100
@@ -1747,6 +1747,26 @@ 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, "screen", 6) &&
+ mutt_strncasecmp (ep, "cygwin", 6) &&
+ mutt_strncasecmp (ep, "rxvt", 4) )
+ unset_option (MuttVars[idx]. data);
+
+ }
}
else if (myvar || DTYPE (MuttVars[idx].type) == DT_STR ||
DTYPE (MuttVars[idx].type) == DT_PATH ||
Index: mutt/init.h
===================================================================
--- mutt.orig/init.h 2006-12-12 14:15:03.000000000 +0100
+++ mutt/init.h 2007-02-20 16:47:02.718578240 +0100
@@ -2941,6 +2941,27 @@ struct option_t MuttVars[] = {
** Controls whether mutt writes out the Bcc header when preparing
** messages to be sent. Exim users may wish to unset 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},
+ /* The default must be off to force in the validity checking. */
+ /*
+ ** .pp
+ ** Controls whether mutt sets the xterm title bar and icon name
+ ** (as long as you are in an appropriate terminal).
+ */
+ {"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 }
};
Index: mutt/mutt.h
===================================================================
--- mutt.orig/mutt.h 2007-01-04 15:23:49.000000000 +0100
+++ mutt/mutt.h 2007-01-27 19:33:32.000000000 +0100
@@ -451,6 +451,7 @@ enum
OPTWRAPSEARCH,
OPTWRITEBCC, /* write out a bcc header? */
OPTXMAILER,
+ OPTXTERMSETTITLES,
OPTCRYPTUSEGPGME,
--- a/pager.c 2014-03-12 17:06:17.000000000 +0100
+++ b/pager.c 2014-08-19 21:53:19.000000000 +0200
@@ -47,6 +47,9 @@
#define IsMsgAttach(x) (x && (x)->fp && (x)->bdy && (x)->bdy->hdr)
#define IsHeader(x) (x && (x)->hdr && !(x)->bdy)
+void set_xterm_title_bar(char *title);
+void set_xterm_icon_name(char *name);
+
static const char *Not_available_in_this_menu = N_("Not available in this menu.");
static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
static const char *Function_not_permitted_in_attach_message_mode = N_("Function not permitted in attach-message mode.");
@@ -1812,6 +1815,13 @@
mutt_paddstr (COLS, bn);
}
NORMAL_COLOR;
+ 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);
+ }
}
if ((redraw & REDRAW_INDEX) && index)
Index: mutt/status.c
===================================================================
--- mutt.orig/status.c 2007-01-27 19:33:36.000000000 +0100
+++ mutt/status.c 2007-01-27 19:34:11.000000000 +0100
@@ -191,6 +191,8 @@ status_format_str (char *buf, size_t buf
break;
case 'P':
+ if (!menu)
+ break;
if (menu->top + menu->pagelen >= menu->max)
cp = menu->top ? "end" : "all";
else
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment