1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-06-08 18:18:02 +02:00

52468: save and restore state of correct TTY when using read -s / -d

This commit is contained in:
Bart Schaefer 2024-01-24 17:27:41 -08:00
parent dde12593db
commit 3406089647
3 changed files with 34 additions and 15 deletions

View file

@ -1,3 +1,8 @@
2024-01-24 Bart Schaefer <schaefer@zsh.org>
* 52468: Src/builtin.c, Src/utils.c: save and restore state of
correct TTY when using read -s / -d
2024-01-14 Matthew Martin <phy1729@gmail.com> 2024-01-14 Matthew Martin <phy1729@gmail.com>
* github #109: Wu Zhenyu: Completion/Linux/Command/_valgrind: Fix * github #109: Wu Zhenyu: Completion/Linux/Command/_valgrind: Fix

View file

@ -6506,10 +6506,10 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
} else } else
readfd = izle = 0; readfd = izle = 0;
if (OPT_ISSET(ops,'s') && SHTTY == readfd) { if (OPT_ISSET(ops,'s') && isatty(readfd)) {
struct ttyinfo ti; struct ttyinfo ti;
memset(&ti, 0, sizeof(struct ttyinfo)); memset(&ti, 0, sizeof(struct ttyinfo));
gettyinfo(&ti); fdgettyinfo(readfd, &ti);
saveti = ti; saveti = ti;
resettty = 1; resettty = 1;
#ifdef HAS_TIO #ifdef HAS_TIO
@ -6517,7 +6517,7 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
#else #else
ti.sgttyb.sg_flags &= ~ECHO; ti.sgttyb.sg_flags &= ~ECHO;
#endif #endif
settyinfo(&ti); fdsettyinfo(readfd, &ti);
} }
/* handle prompt */ /* handle prompt */
@ -6555,9 +6555,9 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
delim = (unsigned char) ((delimstr[0] == Meta) ? delim = (unsigned char) ((delimstr[0] == Meta) ?
delimstr[1] ^ 32 : delimstr[0]); delimstr[1] ^ 32 : delimstr[0]);
#endif #endif
if (SHTTY == readfd) { if (isatty(readfd)) {
struct ttyinfo ti; struct ttyinfo ti;
gettyinfo(&ti); fdgettyinfo(readfd, &ti);
if (! resettty) { if (! resettty) {
saveti = ti; saveti = ti;
resettty = 1; resettty = 1;
@ -6569,7 +6569,7 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
#else #else
ti.sgttyb.sg_flags |= CBREAK; ti.sgttyb.sg_flags |= CBREAK;
#endif #endif
settyinfo(&ti); fdsettyinfo(readfd, &ti);
} }
} }
if (OPT_ISSET(ops,'t')) { if (OPT_ISSET(ops,'t')) {
@ -6604,8 +6604,8 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
timeout)) { timeout)) {
if (keys && !zleactive && !isem) if (keys && !zleactive && !isem)
settyinfo(&shttyinfo); settyinfo(&shttyinfo);
else if (resettty && SHTTY != -1) else if (resettty)
settyinfo(&saveti); fdsettyinfo(readfd, &saveti);
if (haso) { if (haso) {
if (shout) if (shout)
fclose(shout); fclose(shout);
@ -6717,7 +6717,7 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
if (isem) if (isem)
while (val > 0 && read(SHTTY, &d, 1) == 1 && d != '\n'); while (val > 0 && read(SHTTY, &d, 1) == 1 && d != '\n');
else if (resettty) { else if (resettty) {
settyinfo(&shttyinfo); fdsettyinfo(readfd, &saveti);
resettty = 0; resettty = 0;
} }
if (haso) { if (haso) {
@ -6746,8 +6746,8 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
setsparam(reply, metafy(buf, bptr - buf, META_REALLOC)); setsparam(reply, metafy(buf, bptr - buf, META_REALLOC));
else else
zfree(buf, bptr - buf + 1); zfree(buf, bptr - buf + 1);
if (resettty && SHTTY != -1) if (resettty)
settyinfo(&saveti); fdsettyinfo(readfd, &saveti);
return eof; return eof;
} }
@ -6957,8 +6957,8 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
*pp++ = NULL; *pp++ = NULL;
setaparam(reply, p); setaparam(reply, p);
} }
if (resettty && SHTTY != -1) if (resettty)
settyinfo(&saveti); fdsettyinfo(readfd, &saveti);
return c == EOF; return c == EOF;
} }
buf = bptr = (char *)zalloc(bsiz = 64); buf = bptr = (char *)zalloc(bsiz = 64);
@ -7086,8 +7086,8 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
break; break;
} }
*bptr = '\0'; *bptr = '\0';
if (resettty && SHTTY != -1) if (resettty)
settyinfo(&saveti); fdsettyinfo(readfd, &saveti);
/* final assignment of reply, etc. */ /* final assignment of reply, etc. */
if (OPT_ISSET(ops,'e') || OPT_ISSET(ops,'E')) { if (OPT_ISSET(ops,'e') || OPT_ISSET(ops,'E')) {
zputs(buf, stdout); zputs(buf, stdout);

View file

@ -1730,6 +1730,13 @@ freestr(void *a)
/**/ /**/
mod_export void mod_export void
gettyinfo(struct ttyinfo *ti) gettyinfo(struct ttyinfo *ti)
{
fdgettyinfo(SHTTY, ti);
}
/**/
mod_export void
fdgettyinfo(int SHTTY, struct ttyinfo *ti)
{ {
if (SHTTY != -1) { if (SHTTY != -1) {
#ifdef HAVE_TERMIOS_H #ifdef HAVE_TERMIOS_H
@ -1755,6 +1762,13 @@ gettyinfo(struct ttyinfo *ti)
/**/ /**/
mod_export void mod_export void
settyinfo(struct ttyinfo *ti) settyinfo(struct ttyinfo *ti)
{
fdsettyinfo(SHTTY, ti);
}
/**/
mod_export void
fdsettyinfo(int SHTTY, struct ttyinfo *ti)
{ {
if (SHTTY != -1) { if (SHTTY != -1) {
#ifdef HAVE_TERMIOS_H #ifdef HAVE_TERMIOS_H