Correctly clear line and add progress info - pee - Pee a password manager;Pee - because you have to...
 (HTM) git clone git://vernunftzentrum.de/pee.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit c3b038dc8581a640505209dddde0142e9510afef
 (DIR) parent d8d114a7059a8e42ebc2fcb1b03cc5c87aad5b64
 (HTM) Author: Christian Kellermann <ckeen@pestilenz.org>
       Date:   Mon, 11 Jan 2016 12:55:43 +0100
       
       Correctly clear line and add progress info
       
       Since reading from /dev/random is slow we add a progress information
       string.
       
       Diffstat:
         pee.scm                             |      16 +++++++++++-----
       
       1 file changed, 11 insertions(+), 5 deletions(-)
       ---
 (DIR) diff --git a/pee.scm b/pee.scm
       @@ -28,10 +28,12 @@
        (define wanted-entropy (* 20 8))
        
        (define (generate-new-password wanted-entropy)
       -  (define (new-indices len)
       -    (let loop ((len len)
       +  (define (new-indices count)
       +    (let loop ((len count)
                       (idx '()))
       -      (cond ((zero? len) idx)
       +      (clear-line)
       +      (printf "~a/~a random bytes recieved.~!" (- count len) count)
       +      (cond ((zero? len) (clear-line) idx)
                    (else
                     (let ((new (filter (lambda (n)
                                          (< n (string-length password-chars)))
       @@ -55,13 +57,17 @@
           '(not echo icanon opost)
           (lambda ()
             (let loop ()
       +       (clear-line)
               (printf "~a [~a]: " msg (apply string-append options))
               (let ((answer (string (read-char))))
                 (cond ((member answer options) =>
                        (lambda (c)
       -                  (printf "\r")
       +                  (clear-line)
                          (car (string->list (car c)))))
       -               (else (printf "\r") (loop))))))))
       +               (else (loop))))))))
       +
       +(define (clear-line)
       +  (printf "\r~a" (string #\escape #\[ #\K)))
        
        (define (ask-yes-or-no msg)
          (eqv? #\y (ask-for-choice msg "y" "n")))