| 1 |
;; Example of gauche.termios |
| 2 |
|
| 3 |
#!no-fold-case |
| 4 |
|
| 5 |
(use gauche.termios) |
| 6 |
|
| 7 |
(define (get-password prompt) |
| 8 |
(let* ((port (current-input-port)) |
| 9 |
(attr (sys-tcgetattr port)) |
| 10 |
(lflag (slot-ref attr 'lflag))) |
| 11 |
;; Show prompt |
| 12 |
(display prompt) |
| 13 |
(flush) |
| 14 |
;; Turn off echo during reading. |
| 15 |
(dynamic-wind |
| 16 |
(lambda () |
| 17 |
(slot-set! attr 'lflag (logand lflag (lognot ECHO))) |
| 18 |
(sys-tcsetattr port TCSAFLUSH attr)) |
| 19 |
(lambda () |
| 20 |
(read-line port)) |
| 21 |
(lambda () |
| 22 |
(slot-set! attr 'lflag lflag) |
| 23 |
(sys-tcsetattr port TCSANOW attr))))) |