[comp.emacs] reading without echo...

ramin@scampi.UUCP (05/09/87)

Maybe I'm missing something... but is there a way to read in the
minibuffer with echo turned off? That is, to prompt the user for, say,
a password, and read it in without echo...

thanks...

ramin...
---

-- 

{ihnp4,lll-lcc,hoptoad}!scampi!ramin
systems control inc.		(415) 494-1165 x-1777
1801 page mill road		palo alto, ca  94304

nz@hotlg.UUCP (05/13/87)

In article <188@scampi.UUCP> ramin@scampi.UUCP (Fubar Void) writes:
 > Maybe I'm missing something... but is there a way to read in the
 > minibuffer with echo turned off? That is, to prompt the user for, say,
 > a password, and read it in without echo...
 > 
 > ramin...
 > -- 
 > {ihnp4,lll-lcc,hoptoad}!scampi!ramin
 > systems control inc.		(415) 494-1165 x-1777

Ramin,

	I wrote a small package that used such a thing a while ago, but
RMS declined to include it in the 18.4x distribution.  I could not find
a way to accomplish the read purely in Elisp, so I did it in C. 
Here is a useful routine that was part of the terminal-lock package:


DEFUN ("read-string-silent", Fread_string_silent, Sread_string_silent, 1, 1, 0,
   "Read a string from the terminal, no echo, return result on seeing CHAR.\
  Maximum length of the string is same as maximum width of screen.")
       (rc)
       Lisp_Object rc;
{
    int  ic, icret;
    char is[MScreenWidth];
    int  ndex;
    Lisp_Object ret, justread;

    icret = XINT (rc);
    for(ndex = 0, ic = icret + 1; ic != icret; ) {
	justread = Fread_char ();
	ic = XINT (justread);
	if (ndex < (MScreenWidth - 1)) {
	    is[ndex] = (char) ic;
	    ndex++;
	}
    }

    is[ndex] = '\0';
    ret = build_string (is);

    return ret;
}


Of course, this doesn't do the prompting, but I just use (message x y z)
for that.

If anybody out there in net land is interested in the lock-terminal command
and termlock package, just drop me a letter and I'll send it off to you.

-- 
...nz  (Neal Ziring  @  ATT-BL Holmdel, x2354, 3H-437)
	"You can fit an infinite number of wires into this junction box,
	but we usually don't go that far in practice."
					London Electric Co. Worker, 1880s

matt@oddjob.UChicago.EDU (Schizophrenic Solipsist) (05/13/87)

In article <188@scampi.UUCP> ramin@scampi.UUCP (Fubar Void) writes:
) is there a way to read in the minibuffer with echo turned off?

Hmmm.  Try making a new keymap which has the usually-printing
keys bound to something other than self-insert-command.  That
something should concoct a string from the typein.

			Matt Crawford

jr@ALEXANDER.BBN.COM (John Robinson) (05/14/87)

>> I could not find
>> a way to accomplish the read purely in Elisp, so I did it in C. 

Here's a way in elisp.  Generalization ala read-from-minibuffer is
left as an exercise for the reader.

(defun read-silent (prompt)
  (message prompt)
  (let ((chr (read-char))
	(ans ""))
    (while (not (eq chr ?\r))
      (message prompt)
      (setq ans (concat ans (char-to-string chr)))
      (setq chr (read-char)))
    ans))

/jr
jr@bbn.com or jr@bbnccv.uucp

Without life, there wouldn't be chemical companies.

phr@mit-prep.ARPA (Paul Rubin) (05/14/87)

> 	I wrote a small package that used such a thing a while ago, but
> RMS declined to include it in the 18.4x distribution.  I could not find
> a way to accomplish the read purely in Elisp, so I did it in C. ...

Here is a simple Lisp function that does it.  Enough already, ok?

(defun read-string-no-echo (prompt)
  "Read string from tty, prompting with PROMPT, not echoing chars."
  (let ((c 0)
	(str ""))
    (message prompt)
    (while (/= c ?\r)
      (setq c (read-char))
      (message prompt)
      (if (/= c ?\r)
	  (setq str (concat str (char-to-string c)))))
    (message "")
    str))