You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xtitles.patch 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. From: Cristoph Berg <myon@debian.org>
  2. Date: Thu, 27 Feb 2014 12:25:51 +0100
  3. Subject: xtitles
  4. This is the xterm title patch as found on the mutt mailing lists.
  5. * Changes made:
  6. - 2007-01-27 myon: using %P caused a segfault, updated status.c to catch
  7. menu==NULL.
  8. - 2007-02-20 myon: make the note about the xterm_set_titles defaults a
  9. comment.
  10. - 2008-08-02 myon: move set_xterm_* prototypes into the proper header file
  11. (cleaner code, no functional change, evades conflict with sidebar patch)
  12. Signed-off-by: Matteo F. Vescovi <mfvescovi@gmail.com>
  13. Gbp-Pq: Topic features
  14. ---
  15. curs_main.c | 20 ++++++++++++++++++++
  16. globals.h | 2 ++
  17. init.c | 20 ++++++++++++++++++++
  18. init.h | 21 +++++++++++++++++++++
  19. mutt.h | 1 +
  20. mutt_menu.h | 2 ++
  21. pager.c | 7 +++++++
  22. status.c | 2 ++
  23. 8 files changed, 75 insertions(+)
  24. diff --git a/curs_main.c b/curs_main.c
  25. index aa4b044..16ddbc9 100644
  26. --- a/curs_main.c
  27. +++ b/curs_main.c
  28. @@ -110,6 +110,19 @@ static const char *No_visible = N_("No visible messages.");
  29. extern size_t UngetCount;
  30. +#define ASCII_CTRL_G 0x07
  31. +#define ASCII_CTRL_OPEN_SQUARE_BRAKET 0x1b
  32. +
  33. +void set_xterm_title_bar(char *title)
  34. +{
  35. + fprintf(stderr ,"%c]2;%s%c", ASCII_CTRL_OPEN_SQUARE_BRAKET, title, ASCII_CTRL_G);
  36. +}
  37. +
  38. +void set_xterm_icon_name(char *name)
  39. +{
  40. + fprintf(stderr, "%c]1;%s%c", ASCII_CTRL_OPEN_SQUARE_BRAKET, name, ASCII_CTRL_G);
  41. +}
  42. +
  43. void index_make_entry (char *s, size_t l, MUTTMENU *menu, int num)
  44. {
  45. format_flag flag = M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
  46. @@ -560,6 +573,13 @@ int mutt_index_menu (void)
  47. mutt_paddstr (COLS, buf);
  48. NORMAL_COLOR;
  49. menu->redraw &= ~REDRAW_STATUS;
  50. + if (option(OPTXTERMSETTITLES))
  51. + {
  52. + menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
  53. + set_xterm_title_bar(buf);
  54. + menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
  55. + set_xterm_icon_name(buf);
  56. + }
  57. }
  58. menu->redraw = 0;
  59. diff --git a/globals.h b/globals.h
  60. index 6fefe5b..584cd0c 100644
  61. --- a/globals.h
  62. +++ b/globals.h
  63. @@ -141,6 +141,8 @@ WHERE char *Tempdir;
  64. WHERE char *Tochars;
  65. WHERE char *Username;
  66. WHERE char *Visual;
  67. +WHERE char *XtermTitle;
  68. +WHERE char *XtermIcon;
  69. WHERE char *CurrentFolder;
  70. WHERE char *LastFolder;
  71. diff --git a/init.c b/init.c
  72. index cc3cf4b..81bb9e7 100644
  73. --- a/init.c
  74. +++ b/init.c
  75. @@ -1877,6 +1877,26 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
  76. toggle_option (MuttVars[idx].data);
  77. else
  78. set_option (MuttVars[idx].data);
  79. +
  80. + /* sanity check for xterm */
  81. + if ((mutt_strcmp (MuttVars[idx].option, "xterm_set_titles") == 0)
  82. + && option (OPTXTERMSETTITLES))
  83. + {
  84. + char *ep = getenv ("TERM");
  85. + /* Make sure that the terminal can take the control codes */
  86. + if (ep == NULL) unset_option (MuttVars[idx].data);
  87. + else if (mutt_strncasecmp (ep, "xterm", 5) &&
  88. + mutt_strncasecmp (ep, "color-xterm", 11) &&
  89. + mutt_strncasecmp (ep, "eterm", 5) &&
  90. + mutt_strncasecmp (ep, "kterm", 5) &&
  91. + mutt_strncasecmp (ep, "nxterm", 6) &&
  92. + mutt_strncasecmp (ep, "putty", 5) &&
  93. + mutt_strncasecmp (ep, "screen", 6) &&
  94. + mutt_strncasecmp (ep, "cygwin", 6) &&
  95. + mutt_strncasecmp (ep, "rxvt", 4) )
  96. + unset_option (MuttVars[idx]. data);
  97. +
  98. + }
  99. }
  100. else if (myvar || DTYPE (MuttVars[idx].type) == DT_STR ||
  101. DTYPE (MuttVars[idx].type) == DT_PATH ||
  102. diff --git a/init.h b/init.h
  103. index 80d05ce..cf8e75a 100644
  104. --- a/init.h
  105. +++ b/init.h
  106. @@ -3412,6 +3412,27 @@ struct option_t MuttVars[] = {
  107. ** Also see the $$read_inc, $$net_inc and $$time_inc variables and the
  108. ** ``$tuning'' section of the manual for performance considerations.
  109. */
  110. + {"xterm_icon", DT_STR, R_BOTH, UL &XtermIcon, UL "M%?n?AIL&ail?"},
  111. + /*
  112. + ** .pp
  113. + ** Controls the format of the icon title, as long as xterm_set_titles
  114. + ** is enabled. This string is identical in formatting to the one used by
  115. + ** ``$$status_format''.
  116. + */
  117. + {"xterm_set_titles", DT_BOOL, R_BOTH, OPTXTERMSETTITLES, 0},
  118. + /* The default must be off to force in the validity checking. */
  119. + /*
  120. + ** .pp
  121. + ** Controls whether mutt sets the xterm title bar and icon name
  122. + ** (as long as you are in an appropriate terminal).
  123. + */
  124. + {"xterm_title", DT_STR, R_BOTH, UL &XtermTitle, UL "Mutt with %?m?%m messages&no messages?%?n? [%n NEW]?"},
  125. + /*
  126. + ** .pp
  127. + ** Controls the format of the title bar of the xterm provided that
  128. + ** xterm_set_titles has been set. This string is identical in formatting
  129. + ** to the one used by ``$$status_format''.
  130. + */
  131. /*--*/
  132. { NULL, 0, 0, 0, 0 }
  133. };
  134. diff --git a/mutt.h b/mutt.h
  135. index dcd7dc5..1d7e177 100644
  136. --- a/mutt.h
  137. +++ b/mutt.h
  138. @@ -449,6 +449,7 @@ enum
  139. OPTWRAPSEARCH,
  140. OPTWRITEBCC, /* write out a bcc header? */
  141. OPTXMAILER,
  142. + OPTXTERMSETTITLES,
  143. OPTCRYPTUSEGPGME,
  144. OPTCRYPTUSEPKA,
  145. diff --git a/mutt_menu.h b/mutt_menu.h
  146. index d459bef..82abecd 100644
  147. --- a/mutt_menu.h
  148. +++ b/mutt_menu.h
  149. @@ -103,6 +103,8 @@ void menu_current_middle (MUTTMENU *);
  150. void menu_current_bottom (MUTTMENU *);
  151. void menu_check_recenter (MUTTMENU *);
  152. void menu_status_line (char *, size_t, MUTTMENU *, const char *);
  153. +void set_xterm_title_bar (char *title);
  154. +void set_xterm_icon_name (char *name);
  155. MUTTMENU *mutt_new_menu (int);
  156. void mutt_menuDestroy (MUTTMENU **);
  157. diff --git a/pager.c b/pager.c
  158. index 486d8c8..23eb8ca 100644
  159. --- a/pager.c
  160. +++ b/pager.c
  161. @@ -1812,6 +1812,13 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
  162. mutt_paddstr (COLS, bn);
  163. }
  164. NORMAL_COLOR;
  165. + if (option(OPTXTERMSETTITLES))
  166. + {
  167. + menu_status_line (buffer, sizeof (buffer), index, NONULL (XtermTitle));
  168. + set_xterm_title_bar(buffer);
  169. + menu_status_line (buffer, sizeof (buffer), index, NONULL (XtermIcon));
  170. + set_xterm_icon_name(buffer);
  171. + }
  172. }
  173. if ((redraw & REDRAW_INDEX) && index)
  174. diff --git a/status.c b/status.c
  175. index 1bb9a5a..6051e3a 100644
  176. --- a/status.c
  177. +++ b/status.c
  178. @@ -195,6 +195,8 @@ status_format_str (char *buf, size_t buflen, size_t col, char op, const char *sr
  179. break;
  180. case 'P':
  181. + if (!menu)
  182. + break;
  183. if (menu->top + menu->pagelen >= menu->max)
  184. cp = menu->top ? "end" : "all";
  185. else