1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-28 05:00:59 +01:00

zsh-users/12600: reorder handling of -s/-d/-t options so that terminal

input modes are set before attempting a read-poll.  Also display any
prompt before read-polling.  Unposted: remove trailing whitespace from
all lines that had it.
This commit is contained in:
Bart Schaefer 2008-02-18 03:18:03 +00:00
parent 65520f1901
commit 5994edfc88

View file

@ -4822,32 +4822,32 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
} 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 (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);
}
}
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;
}
return 1;
readpmpt[-1] = '\0';
}
}
if (OPT_ISSET(ops,'d')) {
char *delimstr = OPT_ARG(ops,'d');
#ifdef MULTIBYTE_SUPPORT
@ -4870,8 +4870,10 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
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 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
settyinfo(&ti);
}
}
if (OPT_ISSET(ops,'s') && SHTTY != -1) {
struct ttyinfo ti;
gettyinfo(&ti);
if (! resettty) {
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);
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;
}
readpmpt[-1] = '\0';
}
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;
}
return 1;
}
}