about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2002-08-22 12:57:43 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2002-08-22 12:57:43 +0000
commit7123f4413bd02e2ae9a9f762012ba7906b0e7bfd (patch)
tree761f18f0d80c4b01a1df90ad38d072bdadcb776f
parent1c5d5bb1f4a2552364d96acfd5c9f6dbd25aaa80 (diff)
downloadzsh-7123f4413bd02e2ae9a9f762012ba7906b0e7bfd.tar.gz
zsh-7123f4413bd02e2ae9a9f762012ba7906b0e7bfd.tar.xz
zsh-7123f4413bd02e2ae9a9f762012ba7906b0e7bfd.zip
17544: implement read -s to suppress tty echo
-rw-r--r--ChangeLog4
-rw-r--r--Doc/Zsh/builtins.yo8
-rw-r--r--Src/builtin.c29
3 files changed, 36 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index b6e7d5d6b..2392fdbd2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 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,
 	Doc/Zsh/mod_socket.yo:  Don't use predefined name `sun'; set
 	length parameter for accept(); fix inclusion of socket module
diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 88e7e266f..5c084302d 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -811,8 +811,8 @@ contain symbolic links.
 alias(r)(fc -e -)
 findex(read)
 vindex(IFS, use of)
-ifzman(xitem(tt(read) [ tt(-rzpqAclneEt) ] [ 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) ...  ])(
+ifzman(xitem(tt(read) [ tt(-rszpqAclneEt) ] [ tt(-k) [ var(num) ] ]))
+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)
 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
 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))(
 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.
diff --git a/Src/builtin.c b/Src/builtin.c
index f31c38925..a8174a2bc 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -100,7 +100,7 @@ static struct builtin builtins[] =
     BUILTIN("pushln", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, NULL, "-nz"),
     BUILTIN("pwd", 0, bin_pwd, 0, 0, 0, "rLP", 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("rehash", 0, bin_hash, 0, 0, 0, "df", "r"),
     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;
     LinkList readll = newlinklist();
     FILE *oshout = NULL;
-    int readchar = -1, val;
+    int readchar = -1, val, resettty = 0;
+    struct ttyinfo saveti;
     char d;
 
 
@@ -3955,6 +3956,18 @@ bin_read(char *name, char **args, char *ops, int func)
 	}
 	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 */
     if (firstarg) {
@@ -4001,8 +4014,10 @@ bin_read(char *name, char **args, char *ops, int func)
 	    /* dispose of result appropriately, etc. */
 	    if (isem)
 		while (val > 0 && read(SHTTY, &d, 1) == 1 && d != '\n');
-	    else
+	    else {
 		settyinfo(&shttyinfo);
+		resettty = 0;
+	    }
 	    if (haso) {
 		fclose(shout);	/* close(SHTTY) */
 		shout = oshout;
@@ -4016,6 +4031,8 @@ bin_read(char *name, char **args, char *ops, int func)
 	    setsparam(reply, metafy(buf, bptr - buf, META_REALLOC));
 	else
 	    zfree(buf, bptr - buf + 1);
+	if (resettty && SHTTY != -1)
+	    settyinfo(&saveti);
 	return val <= 0;
     }
 
@@ -4046,6 +4063,8 @@ bin_read(char *name, char **args, char *ops, int func)
 	if (!ops['e'])
 	    setsparam(reply, ztrdup(readbuf));
 
+	if (resettty && SHTTY != -1)
+	    settyinfo(&saveti);
 	return readbuf[0] == 'n';
     }
 
@@ -4156,6 +4175,8 @@ bin_read(char *name, char **args, char *ops, int func)
 	    *pp++ = NULL;
 	    setaparam(reply, p);
 	}
+	if (resettty && SHTTY != -1)
+	    settyinfo(&saveti);
 	return c == EOF;
     }
     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]))
 	bptr--;
     *bptr = '\0';
+    if (resettty && SHTTY != -1)
+	settyinfo(&saveti);
     /* final assignment of reply, etc. */
     if (ops['e'] || ops['E']) {
 	zputs(buf, stdout);