1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-06-02 21:36:05 +02:00

17544: implement read -s to suppress tty echo

This commit is contained in:
Peter Stephenson 2002-08-22 12:57:43 +00:00
parent 1c5d5bb1f4
commit 7123f4413b
3 changed files with 36 additions and 5 deletions

View File

@ -1,5 +1,9 @@
2002-08-22 Peter Stephenson <pws@csr.com> 2002-08-22 Peter Stephenson <pws@csr.com>
* 17544: Src/builtin.c, Doc/Zsh/builtins.yo: add `read -s' which
suppresses terminal echoing. Doesn't work with -q, no effect if
not a tty.
* 17570: Src/Modules/socket.c, Doc/Zsh/Makefile.in, * 17570: Src/Modules/socket.c, Doc/Zsh/Makefile.in,
Doc/Zsh/mod_socket.yo: Don't use predefined name `sun'; set Doc/Zsh/mod_socket.yo: Don't use predefined name `sun'; set
length parameter for accept(); fix inclusion of socket module length parameter for accept(); fix inclusion of socket module

View File

@ -811,8 +811,8 @@ contain symbolic links.
alias(r)(fc -e -) alias(r)(fc -e -)
findex(read) findex(read)
vindex(IFS, use of) vindex(IFS, use of)
ifzman(xitem(tt(read) [ tt(-rzpqAclneEt) ] [ tt(-k) [ var(num) ] ])) ifzman(xitem(tt(read) [ tt(-rszpqAclneEt) ] [ tt(-k) [ var(num) ] ]))
item(ifnzman(tt(read) [ tt(-rzpqAclneEt) ] [ tt(-k) [ var(num) ] ]) [ tt(-u)var(n) ] [ var(name)[tt(?)var(prompt)] ] [ var(name) ... ])( item(ifnzman(tt(read) [ tt(-rszpqAclneEt) ] [ tt(-k) [ var(num) ] ]) [ tt(-u)var(n) ] [ var(name)[tt(?)var(prompt)] ] [ var(name) ... ])(
vindex(REPLY, use of) vindex(REPLY, use of)
vindex(reply, use of) vindex(reply, use of)
Read one line and break it into fields using the characters Read one line and break it into fields using the characters
@ -829,6 +829,10 @@ Raw mode: a `tt(\)' at the end of a line does not signify line
continuation and backslashes in the line don't quote the following continuation and backslashes in the line don't quote the following
character and are not removed. character and are not removed.
) )
item(tt(-s))(
Don't echo back characters if reading from the terminal. Currently does
not work with the tt(-q) option.
)
item(tt(-q))( item(tt(-q))(
Read only one character from the terminal and set var(name) to Read only one character from the terminal and set var(name) to
`tt(y)' if this character was `tt(y)' or `tt(Y)' and to `tt(n)' otherwise. `tt(y)' if this character was `tt(y)' or `tt(Y)' and to `tt(n)' otherwise.

View File

@ -100,7 +100,7 @@ static struct builtin builtins[] =
BUILTIN("pushln", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, NULL, "-nz"), BUILTIN("pushln", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, NULL, "-nz"),
BUILTIN("pwd", 0, bin_pwd, 0, 0, 0, "rLP", NULL), BUILTIN("pwd", 0, bin_pwd, 0, 0, 0, "rLP", NULL),
BUILTIN("r", BINF_R, bin_fc, 0, -1, BIN_FC, "nrl", NULL), BUILTIN("r", BINF_R, bin_fc, 0, -1, BIN_FC, "nrl", NULL),
BUILTIN("read", 0, bin_read, 0, -1, 0, "ceklnpqrtzuAE0123456789", NULL), BUILTIN("read", 0, bin_read, 0, -1, 0, "ceklnpqrstzuAE0123456789", NULL),
BUILTIN("readonly", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "AEFHLRTUZafghilptux", "r"), BUILTIN("readonly", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "AEFHLRTUZafghilptux", "r"),
BUILTIN("rehash", 0, bin_hash, 0, 0, 0, "df", "r"), BUILTIN("rehash", 0, bin_hash, 0, 0, 0, "df", "r"),
BUILTIN("return", BINF_PSPECIAL, bin_break, 0, 1, BIN_RETURN, NULL, NULL), BUILTIN("return", BINF_PSPECIAL, bin_break, 0, 1, BIN_RETURN, NULL, NULL),
@ -3882,7 +3882,8 @@ bin_read(char *name, char **args, char *ops, int func)
char *buf, *bptr, *firstarg, *zbuforig; char *buf, *bptr, *firstarg, *zbuforig;
LinkList readll = newlinklist(); LinkList readll = newlinklist();
FILE *oshout = NULL; FILE *oshout = NULL;
int readchar = -1, val; int readchar = -1, val, resettty = 0;
struct ttyinfo saveti;
char d; char d;
@ -3955,6 +3956,18 @@ bin_read(char *name, char **args, char *ops, int func)
} }
return 1; return 1;
} }
if (ops['s'] && SHTTY != -1) {
struct ttyinfo ti;
gettyinfo(&ti);
saveti = ti;
#ifdef HAS_TIO
ti.tio.c_lflag &= ~ECHO;
#else
ti.sgttyb.sg_flags &= ~ECHO;
#endif
settyinfo(&ti);
resettty = 1;
}
/* handle prompt */ /* handle prompt */
if (firstarg) { if (firstarg) {
@ -4001,8 +4014,10 @@ bin_read(char *name, char **args, char *ops, int func)
/* dispose of result appropriately, etc. */ /* dispose of result appropriately, etc. */
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 else {
settyinfo(&shttyinfo); settyinfo(&shttyinfo);
resettty = 0;
}
if (haso) { if (haso) {
fclose(shout); /* close(SHTTY) */ fclose(shout); /* close(SHTTY) */
shout = oshout; shout = oshout;
@ -4016,6 +4031,8 @@ bin_read(char *name, char **args, char *ops, 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)
settyinfo(&saveti);
return val <= 0; return val <= 0;
} }
@ -4046,6 +4063,8 @@ bin_read(char *name, char **args, char *ops, int func)
if (!ops['e']) if (!ops['e'])
setsparam(reply, ztrdup(readbuf)); setsparam(reply, ztrdup(readbuf));
if (resettty && SHTTY != -1)
settyinfo(&saveti);
return readbuf[0] == 'n'; return readbuf[0] == 'n';
} }
@ -4156,6 +4175,8 @@ bin_read(char *name, char **args, char *ops, int func)
*pp++ = NULL; *pp++ = NULL;
setaparam(reply, p); setaparam(reply, p);
} }
if (resettty && SHTTY != -1)
settyinfo(&saveti);
return c == EOF; return c == EOF;
} }
buf = bptr = (char *)zalloc(bsiz = 64); buf = bptr = (char *)zalloc(bsiz = 64);
@ -4202,6 +4223,8 @@ bin_read(char *name, char **args, char *ops, int func)
while (bptr > buf && iwsep(bptr[-1])) while (bptr > buf && iwsep(bptr[-1]))
bptr--; bptr--;
*bptr = '\0'; *bptr = '\0';
if (resettty && SHTTY != -1)
settyinfo(&saveti);
/* final assignment of reply, etc. */ /* final assignment of reply, etc. */
if (ops['e'] || ops['E']) { if (ops['e'] || ops['E']) {
zputs(buf, stdout); zputs(buf, stdout);