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

Re: xterm title (What should go into 1.5.7?)



On Fri, 28 Jan 2005, Christoph Berg wrote:
> It seems that it is currently impossible to include ESC in
> status_format, at least when entered from the : prompt. It just shows
> "^[" in the status line. Not being able to edit settings from within
> mutt would be bad. Depending on how much of the status_format code had
> to be changed, I still think that part of that should go into mutt
> itself and not entirely moved to a sh script. Will look into the code
> after the weekend.

Already done?
If not, I give you my patch.

Side effect: mutt_paddstr() always changes xtitle.

-- 
tamo
--- /home/tamo/cvs/mutt/curs_lib.c      2005-01-29 19:07:01.000000000 +0900
+++ curs_lib.c  2005-02-08 02:47:55.447544848 +0900
@@ -571,6 +571,24 @@
     return addstr (buf);
 }
 
+static size_t check_xtitles (const char *buf)
+{
+  mbstate_t mbstate;
+  wchar_t wc;
+  size_t k, n, count = 1; /* allow empty title */
+
+  memset (&mbstate, 0, sizeof (mbstate));
+  for (n = mutt_strlen (buf);
+       n && (k = mbrtowc (&wc, buf, n, &mbstate));
+       buf += k, n -= k, count += k)
+  {
+    if (k == (size_t)(-1) || k == (size_t)(-2) || n < k)
+      return 0;
+    if (wc == 7)
+      return count;
+  }
+  return 0;
+}
 
 /*
  * This formats a string, a bit like
@@ -700,7 +718,7 @@
 {
   wchar_t wc;
   int w;
-  size_t k;
+  size_t k, titlelen;
   size_t len = mutt_strlen (s);
   mbstate_t mbstate;
 
@@ -712,6 +730,19 @@
       k = (k == (size_t)(-1)) ? 1 : len;
       wc = replacement_char ();
     }
+    /* Handle xtitles */
+    if (wc == 0x1b && s[1] == ']' &&
+       (s[2] == '0' /*|| s[2] == '1' || s[2] == '2'*/) &&
+       s[3] == ';' && (titlelen = check_xtitles (s+4)))
+    {
+      char *titleseq = safe_malloc (titlelen + 5);
+      strncpy (titleseq, s, titlelen + 4);
+      titleseq[titlelen + 5] = '\0';
+      fputs (titleseq, stderr);
+      FREE (&titleseq);
+      k += (titlelen + 3);
+      continue;
+    }
     if (!IsWPrint (wc))
       wc = '?';
     w = wcwidth (wc);