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

Re: read -s doesn't work with -t?



On Feb 16,  8:50am, Mikael Magnusson wrote:
}
} Maybe this is overly naive, but the following seems to fix the issue
} for me. That is, just moving the code for -s up above the code for -t.

No, that isn't enough.  That moves -s above -d as well, and the code
for -d saves and restores the tty state; so if -s has already set
~ECHO then the tty will be restored incorrectly if you use -s and -d.

It also seems to me that canonical input mode should be set and the
prompt should be printed before the read-timeout poll is done, so -d
should come before -t as well.  However, I'm not really sure what's
going on with shttyinfo versus saveti, so I'm not going to commit the
following until somebody else checks it over.

And of course there may be some kind of bad interaction between changing
the tty state and reading typeahead that I'm not aware of that makes all
this impossible, in which case it should just be documented that you
can't use a prompt or -s or -d in combination with -t.

HOWEVER, this patch *does* solve my problem from zsh-workers/24409, if I
use "read -st 2 -rk ..." in the xterm-ask function.  So I think this is
at least on the right track.


Index: Src/builtin.c
--- zsh-forge/current/Src/builtin.c	2008-01-26 17:42:21.000000000 -0800
+++ zsh-4.3/Src/builtin.c	2008-02-16 09:25:02.000000000 -0800
@@ -4822,32 +4822,32 @@
     } else
 	readfd = izle = 0;
 
-    if (OPT_ISSET(ops,'t')) {
-	zlong timeout = 0;
-	if (OPT_HASARG(ops,'t')) {
-	    mnumber mn = zero_mnumber;
-	    mn = matheval(OPT_ARG(ops,'t'));
-	    if (errflag)
-		return 1;
-	    if (mn.type == MN_FLOAT) {
-		mn.u.d *= 1e6;
-		timeout = (zlong)mn.u.d;
-	    } else {
-		timeout = (zlong)mn.u.l * (zlong)1000000;
-	    }
-	}
-	if (readfd == -1 ||
-	    !read_poll(readfd, &readchar, keys && !zleactive, timeout)) {
-	    if (OPT_ISSET(ops,'k') && !zleactive && !isem)
-		settyinfo(&shttyinfo);
-	    if (haso) {
-		fclose(shout);
-		shout = oshout;
-		SHTTY = -1;
+    if (OPT_ISSET(ops,'s') && SHTTY != -1) {
+	struct ttyinfo ti;
+	gettyinfo(&ti);
+	saveti = ti;
+	resettty = 1;
+#ifdef HAS_TIO
+	ti.tio.c_lflag &= ~ECHO;
+#else
+	ti.sgttyb.sg_flags &= ~ECHO;
+#endif
+	settyinfo(&ti);
+    }
+
+    /* handle prompt */
+    if (firstarg) {
+	for (readpmpt = firstarg;
+	     *readpmpt && *readpmpt != '?'; readpmpt++);
+	if (*readpmpt++) {
+	    if (keys || isatty(0)) {
+		zputs(readpmpt, (shout ? shout : stderr));
+		fflush(shout ? shout : stderr);
 	    }
-	    return 1;
+	    readpmpt[-1] = '\0';
 	}
     }
+
     if (OPT_ISSET(ops,'d')) {
 	char *delimstr = OPT_ARG(ops,'d');
 #ifdef MULTIBYTE_SUPPORT
@@ -4870,8 +4870,10 @@
 	if (SHTTY != -1) {
 	    struct ttyinfo ti;
 	    gettyinfo(&ti);
-	    saveti = ti;
-	    resettty = 1;
+	    if (! resettty) {
+		saveti = ti;
+		resettty = 1;
+	    }
 #ifdef HAS_TIO
 	    ti.tio.c_lflag &= ~ICANON;
 	    ti.tio.c_cc[VMIN] = 1;
@@ -4882,31 +4884,32 @@
 	    settyinfo(&ti);
 	}
     }
-    if (OPT_ISSET(ops,'s') && SHTTY != -1) {
-	struct ttyinfo ti;
-	gettyinfo(&ti);
-	if (! resettty) {
-	    saveti = ti;
-	    resettty = 1;
+    if (OPT_ISSET(ops,'t')) {
+	zlong timeout = 0;
+	if (OPT_HASARG(ops,'t')) {
+	    mnumber mn = zero_mnumber;
+	    mn = matheval(OPT_ARG(ops,'t'));
+	    if (errflag)
+		return 1;
+	    if (mn.type == MN_FLOAT) {
+		mn.u.d *= 1e6;
+		timeout = (zlong)mn.u.d;
+	    } else {
+		timeout = (zlong)mn.u.l * (zlong)1000000;
+	    }
 	}
-#ifdef HAS_TIO
-	ti.tio.c_lflag &= ~ECHO;
-#else
-	ti.sgttyb.sg_flags &= ~ECHO;
-#endif
-	settyinfo(&ti);
-    }
-
-    /* handle prompt */
-    if (firstarg) {
-	for (readpmpt = firstarg;
-	     *readpmpt && *readpmpt != '?'; readpmpt++);
-	if (*readpmpt++) {
-	    if (keys || isatty(0)) {
-		zputs(readpmpt, (shout ? shout : stderr));
-		fflush(shout ? shout : stderr);
+	if (readfd == -1 ||
+	    !read_poll(readfd, &readchar, keys && !zleactive, timeout)) {
+	    if (OPT_ISSET(ops,'k') && !zleactive && !isem)
+		settyinfo(&shttyinfo);
+	    else if (resettty && SHTTY != -1)
+		settyinfo(&saveti);
+	    if (haso) {
+		fclose(shout);
+		shout = oshout;
+		SHTTY = -1;
 	    }
-	    readpmpt[-1] = '\0';
+	    return 1;
 	}
     }
 

-- 



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