Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: read -s doesn't work with -t?
- X-seq: zsh-users 12600
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: "zsh users" <zsh-users@xxxxxxxxxx>
- Subject: Re: read -s doesn't work with -t?
- Date: Sat, 16 Feb 2008 09:37:53 -0800
- In-reply-to: <237967ef0802152350i1fec3369oba9268400a209b2e@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <237967ef0802151327q1c6d3a19oa67a977b82c52f67@xxxxxxxxxxxxxx> <080215191216.ZM29994@xxxxxxxxxxxxxxxxxxxxxx> <237967ef0802152333g7f759674r806f61f9f76f86f2@xxxxxxxxxxxxxx> <237967ef0802152350i1fec3369oba9268400a209b2e@xxxxxxxxxxxxxx>
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