Mercurial > emacs
comparison lisp/comint.el @ 57539:8c6fc4afae74
(comint-output-filter-functions): Add comint-watch-for-password-prompt.
(comint-read-noecho): Function deleted.
(send-invisible): Use read-passwd.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 17 Oct 2004 06:51:10 +0000 |
parents | bcfb3a26a3bd |
children | bdfa227d18a8 |
comparison
equal
deleted
inserted
replaced
57538:6f85a547ab10 | 57539:8c6fc4afae74 |
---|---|
370 | 370 |
371 (defvar comint-input-filter-functions '() | 371 (defvar comint-input-filter-functions '() |
372 "Special hook run before input is sent to the process. | 372 "Special hook run before input is sent to the process. |
373 These functions get one argument, a string containing the text to send.") | 373 These functions get one argument, a string containing the text to send.") |
374 | 374 |
375 (defvar comint-output-filter-functions '(comint-postoutput-scroll-to-bottom) | 375 (defvar comint-output-filter-functions '(comint-postoutput-scroll-to-bottom comint-watch-for-password-prompt) |
376 "Functions to call after output is inserted into the buffer. | 376 "Functions to call after output is inserted into the buffer. |
377 One possible function is `comint-postoutput-scroll-to-bottom'. | 377 One possible function is `comint-postoutput-scroll-to-bottom'. |
378 These functions get one argument, a string containing the text as originally | 378 These functions get one argument, a string containing the text as originally |
379 inserted. Note that this might not be the same as the buffer contents between | 379 inserted. Note that this might not be the same as the buffer contents between |
380 `comint-last-output-start' and the buffer's `process-mark', if other filter | 380 `comint-last-output-start' and the buffer's `process-mark', if other filter |
1899 (forward-line 0) | 1899 (forward-line 0) |
1900 (goto-char (comint-line-beginning-position)))) | 1900 (goto-char (comint-line-beginning-position)))) |
1901 | 1901 |
1902 ;; These three functions are for entering text you don't want echoed or | 1902 ;; These three functions are for entering text you don't want echoed or |
1903 ;; saved -- typically passwords to ftp, telnet, or somesuch. | 1903 ;; saved -- typically passwords to ftp, telnet, or somesuch. |
1904 ;; Just enter m-x send-invisible and type in your line, or add | 1904 ;; Just enter m-x send-invisible and type in your line. |
1905 ;; `comint-watch-for-password-prompt' to `comint-output-filter-functions'. | |
1906 | |
1907 (defun comint-read-noecho (prompt &optional stars) | |
1908 "Read a single line of text from user without echoing, and return it. | |
1909 Prompt with argument PROMPT, a string. Optional argument STARS causes | |
1910 input to be echoed with '*' characters on the prompt line. Input ends with | |
1911 RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. C-g aborts (if | |
1912 `inhibit-quit' is set because e.g. this function was called from a process | |
1913 filter and C-g is pressed, this function returns nil rather than a string). | |
1914 | |
1915 Note that the keystrokes comprising the text can still be recovered | |
1916 \(temporarily) with \\[view-lossage]. Some people find this worrisome (see, | |
1917 however, `clear-this-command-keys'). | |
1918 Once the caller uses the password, it can erase the password | |
1919 by doing (clear-string STRING)." | |
1920 (let ((ans "") | |
1921 (newans nil) | |
1922 (c 0) | |
1923 (echo-keystrokes 0) | |
1924 (cursor-in-echo-area t) | |
1925 (message-log-max nil) | |
1926 (done nil)) | |
1927 (while (not done) | |
1928 (if stars | |
1929 (message "%s%s" prompt (make-string (length ans) ?*)) | |
1930 (message "%s" prompt)) | |
1931 ;; Use this instead of `read-char' to avoid "Non-character input-event". | |
1932 (setq c (read-char-exclusive)) | |
1933 (cond ((= c ?\C-g) | |
1934 ;; This function may get called from a process filter, where | |
1935 ;; inhibit-quit is set. In later versions of emacs read-char | |
1936 ;; may clear quit-flag itself and return C-g. That would make | |
1937 ;; it impossible to quit this loop in a simple way, so | |
1938 ;; re-enable it here (for backward-compatibility the check for | |
1939 ;; quit-flag below would still be necessary, so this seems | |
1940 ;; like the simplest way to do things). | |
1941 (setq quit-flag t | |
1942 done t)) | |
1943 ((or (= c ?\r) (= c ?\n) (= c ?\e)) | |
1944 (setq done t)) | |
1945 ((= c ?\C-u) | |
1946 (clear-string ans) | |
1947 (setq ans "")) | |
1948 ((and (/= c ?\b) (/= c ?\177)) | |
1949 (setq newans (concat ans (char-to-string c))) | |
1950 (clear-string ans) | |
1951 (setq ans newans)) | |
1952 ((> (length ans) 0) | |
1953 (aset ans (1- (length ans)) 0) | |
1954 (setq ans (substring ans 0 -1))))) | |
1955 (if quit-flag | |
1956 ;; Emulate a true quit, except that we have to return a value. | |
1957 (prog1 | |
1958 (setq quit-flag nil) | |
1959 (message "Quit") | |
1960 (beep t)) | |
1961 (message "") | |
1962 ans))) | |
1963 | 1905 |
1964 (defun send-invisible (&optional prompt) | 1906 (defun send-invisible (&optional prompt) |
1965 "Read a string without echoing. | 1907 "Read a string without echoing. |
1966 Then send it to the process running in the current buffer. | 1908 Then send it to the process running in the current buffer. |
1967 The string is sent using `comint-input-sender'. | 1909 The string is sent using `comint-input-sender'. |
1968 Security bug: your string can still be temporarily recovered with | 1910 Security bug: your string can still be temporarily recovered with |
1969 \\[view-lossage]; `clear-this-command-keys' can fix that." | 1911 \\[view-lossage]; `clear-this-command-keys' can fix that." |
1970 (interactive "P") ; Defeat snooping via C-x ESC ESC | 1912 (interactive "P") ; Defeat snooping via C-x ESC ESC |
1971 (let ((proc (get-buffer-process (current-buffer)))) | 1913 (let ((proc (get-buffer-process (current-buffer)))) |
1972 (if proc | 1914 (if proc |
1973 (let ((str (comint-read-noecho (or prompt "Non-echoed text: ") t))) | 1915 (let ((str (read-passwd (or prompt "Non-echoed text: ")))) |
1974 (if (stringp str) | 1916 (if (stringp str) |
1975 (progn | 1917 (progn |
1976 (comint-snapshot-last-prompt) | 1918 (comint-snapshot-last-prompt) |
1977 (funcall comint-input-sender proc str)) | 1919 (funcall comint-input-sender proc str)) |
1978 (message "Warning: text will be echoed"))) | 1920 (message "Warning: text will be echoed"))) |