Re: Xterm title [PATCH included]



On Fri, Dec 27, 2002 at 03:54:05PM +0100, Thomas Zajic wrote:
> I really like mc's new feature to set the Xterm title to mc's current
> directory. Still, I've got one minor cosmetical request concerning this
> feature: would it be possible to save the original Xterm title when mc
> starts, and restore it when mc quits?

I guess attached patch could be helpful for you. 

I've tested this feature on:
- xterm, rxvt (no problems)
- aterm (stores initial window title, not the current one)

BTW it doesn't restore title when one turns 'xterm window title' off.
When somebody turns this off - it means he has a purpose.

I'm sending this patch to mc BTS, maybe Pavel will consider including
it to 4.6.0 when he returns.

HTH
Regards


-- 

  _.|._ |_  _.    : Adam Byrtek, alpha@(irc.pl|debian.org)
 (_|||_)| |(_|    : gg 1802819, pgp 0xB25952C0
     |            : jid alpha.pl(at)jabber.org
Index: src/main.c
===================================================================
RCS file: /cvs/gnome/mc/src/main.c,v
retrieving revision 1.272
diff -u -r1.272 main.c
--- src/main.c	27 Dec 2002 23:23:34 -0000	1.272
+++ src/main.c	29 Dec 2002 13:02:17 -0000
@@ -2403,11 +2403,45 @@
 }
 #endif				/* NATIVE_WIN32 */
 
+/* Remember old xterm widow title. Tested on xterm, rxvt (works well)
+ * and aterm (stores inital title, not the current one). */
+unsigned char *
+store_xterm_title (void)
+{
+    static unsigned char title[255];
+    int c, i = 0;
+
+    printf ("\e[21t");
+    fflush (stdout);
+    
+    nodelay (stdscr, TRUE);
+    while (i < 255 && (c=getch()) != -1) {
+	title[i++] = c;
+    }
+    nodelay (stdscr, FALSE);
+
+    /* strip leading \e[l and trailing \e] */
+    if (i < 5)
+	return NULL;
+    title[i-2] = '\0';
+    return title+3;
+}
+
+void
+restore_xterm_title (unsigned char *title)
+{
+    if (title != NULL) {
+	printf("\e]0;%s\a", title);
+	fflush(stdout);
+    }
+}
+	
 int
 main (int argc, char *argv[])
 {
     /* if on, it displays the information that files have been moved to ~/.mc */
     int show_change_notice = 0;
+    unsigned char *old_xterm_title = NULL;
 
     /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
     setlocale (LC_ALL, "");
@@ -2510,9 +2544,16 @@
 #endif				/* HAVE_SUBSHELL_SUPPORT */
 	prompt = (geteuid () == 0) ? "# " : "$ ";
 
+    /* Must be done be after slang_init, init_curses, init_xterm_support */
+    if (xterm_flag)
+        old_xterm_title = store_xterm_title();
+   
     /* Program main loop */
     do_nc ();
 
+    if (xterm_flag && xterm_title)
+        restore_xterm_title(old_xterm_title);
+   
     /* Save the tree store */
     tree_store_save ();
 
Index: src/ChangeLog
===================================================================
RCS file: /cvs/gnome/mc/src/ChangeLog,v
retrieving revision 1.1088
diff -u -0 -r1.1088 ChangeLog
--- src/ChangeLog	27 Dec 2002 17:52:24 -0000	1.1088
+++ src/ChangeLog	29 Dec 2002 13:03:09 -0000
@@ -0,0 +1,6 @@
+2002-12-29  Adam Byrtek  <alpha debian org>
+
+	* main.c (store_xterm_title, restore_xterm_title): New
+	functions. Xterm window title stored at startup, restored at
+	clean exit (only if xterm_title is set).
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]