Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Can't change stty settings with zle running



On Tue, 18 Dec 2007 00:25:08 +0100
Stefan `Sec` Zehl <sec@xxxxxx> wrote:
> I was trying to change a stty setting from within a signal handler:
>...
> Ok. After some experimenting, I now understand, that this happens
> because zle is running at that moment.

That's correct.  Zle sets its own terminal settings and basically ignores
the normal state from then on.

> Is it possible to fix zle -I so stty changes will be honored?

That seems pretty reasonable since you've explicitly asked to be given
control of the terminal.  I've added an internal flag for this case; when
zle regains control it will save the current settings.  I tried it a
little, but you probably have a more thorough test.

Index: Src/jobs.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v
retrieving revision 1.60
diff -u -r1.60 jobs.c
--- Src/jobs.c	5 Sep 2007 16:16:17 -0000	1.60
+++ Src/jobs.c	18 Dec 2007 10:20:28 -0000
@@ -93,7 +93,7 @@
 /* 1 if ttyctl -f has been executed */
  
 /**/
-int ttyfrozen;
+mod_export int ttyfrozen;
 
 /* Previous values of errflag and breaks if the signal handler had to
  * change them. And a flag saying if it did that. */
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.101
diff -u -r1.101 zle_main.c
--- Src/Zle/zle_main.c	13 Dec 2007 21:56:18 -0000	1.101
+++ Src/Zle/zle_main.c	18 Dec 2007 10:20:30 -0000
@@ -208,10 +208,21 @@
 zsetterm(void)
 {
     struct ttyinfo ti;
-
 #if defined(FIONREAD)
     int val;
+#endif
 
+    if (fetchttyinfo) {
+	/*
+	 * User requested terminal to be returned to normal use,
+	 * so remember the terminal settings if not frozen.
+	 */
+	if (!ttyfrozen)
+	    gettyinfo(&shttyinfo);
+	fetchttyinfo = 0;
+    }
+
+#if defined(FIONREAD)
     ioctl(SHTTY, FIONREAD, (char *)&val);
     if (val) {
 	/*
@@ -1113,6 +1124,7 @@
     insmode = unset(OVERSTRIKE);
     eofsent = 0;
     resetneeded = 0;
+    fetchttyinfo = 0;
     raw_lp = lp;
     lpromptbuf = promptexpand(lp ? *lp : NULL, 1, NULL, NULL);
     pmpt_attr = txtchange;
Index: Src/Zle/zle_thingy.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_thingy.c,v
retrieving revision 1.32
diff -u -r1.32 zle_thingy.c
--- Src/Zle/zle_thingy.c	29 May 2007 17:01:09 -0000	1.32
+++ Src/Zle/zle_thingy.c	18 Dec 2007 10:20:30 -0000
@@ -711,6 +711,17 @@
     return ret;
 }
 
+
+/*
+ * Flag that the user has requested the terminal be trashed
+ * for whatever use.  We attempt to keep the tty settings in
+ * this mode synced with the normal (non-zle) settings unless
+ * they are frozen.
+ */
+
+/**/
+int fetchttyinfo;
+
 /**/
 static int
 bin_zle_invalidate(UNUSED(char *name), UNUSED(char **args), UNUSED(Options ops), UNUSED(char func))
@@ -721,7 +732,18 @@
      * true if a completion widget is active.
      */
     if (zleactive) {
+	int wastrashed = trashedzle;
 	trashzle();
+	if (!wastrashed && (zlereadflags & ZLRF_NOSETTY)) {
+	    /*
+	     * We normally wouldn't have restored the terminal
+	     * in this case, but as it's at user request we do
+	     * so (hence the apparently illogical sense of the
+	     * second part of the test).
+	     */
+	    settyinfo(&shttyinfo);
+	}
+	fetchttyinfo = 1;
 	return 0;
     } else
 	return 1;


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author