[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



>From info-mcl-owner  Tue Dec 13 11:28:12 1994
Received: from uu3.psi.com (uu3.psi.com [38.145.250.2]) by digitool.com
(8.6.9/A/UX 3.1) with SMTP id LAA02061 for <info-mcl@digitool.com>; Tue, 13
Dec 1994 11:28:08 -0800
Received: from flavors.com by uu3.psi.com (5.65b/4.0.071791-PSI/PSINet) via
SMTP;
        id AA01727 for info-mcl@digitool.com; Tue, 13 Dec 94 14:14:01 -0500
Received: from [204.5.215.11] by flavors.com
 with SMTP (MailShare 1.0b8); Tue, 13 Dec 1994 14:20:21 -0500
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Date: Tue, 13 Dec 1994 14:13:52 -0500
To: pbjakewa@barrow.uwaterloo.ca (Bruce Jakeway)
From: e@flavors.com (Doug Currie, Flavors Technology, Inc.)
Subject: timed-y-or-n-p
Cc: info-mcl@digitool.com
Message-Id: <1424794075-4293440@flavors.com>
Sender: owner-info-mcl@digitool.com
Precedence: bulk

>I would like to read a character from the keyboard but if after a specified
>period of time nothing is inputed, for the character to be defaulted to a
>pre-specified character and the read aborted.  Any help would be appreciated.

This may help you get started.
e

(defun timed-y-or-n-p (&key
                       (time-limit 15)
                       (default nil)
                       (clear-input nil)
                       (beep t)
                       (format-string nil)
                       (format-arguments ()))
  (check-type time-limit (and number (not complex) (satisfies plusp)))
  (loop
    (fresh-line *query-io*)
    (when format-string
      (apply #'format *query-io* format-string format-arguments))
    (format *query-io* " (y or n, Default ~:[~S~;~:[No~;Yes~]~] after ~d
seconds) "
            (or (null default) (eq default t))
            default
            time-limit)
    (when clear-input
      (clear-input *query-io*))
    (when beep
      (#_sysbeep :word 3))
    (macrolet ((prin-default
                   ()
                 `(case default
                    ((t) (princ "Yes." *query-io*))
                    ((nil) (princ "No." *query-io*))
                    (otherwise (prin1 default *query-io*))))
               (result
                   (result)
                 `(return-from timed-y-or-n-p ,result)))
      (DO ((wwkkff (+ (#_TickCount ) (ROUND TIME-LIMIT 1/60))))
          ((>= (CCL::%STACK-TRAP 43381 5) wwkkff)
           (PRIN-DEFAULT)
           (PRINC " (timeout)" *QUERY-IO*)
           (WHEN BEEP (TRAPS:_SYSBEEP :WORD 3))
           (RESULT DEFAULT))
        (CASE (READ-CHAR-NO-HANG *QUERY-IO*)
          ((NIL))
          ((#\Y #\y) (PRINC "es." *QUERY-IO*) (RESULT T))
          ((#\N #\n) (PRINC "o." *QUERY-IO*) (RESULT NIL))
          ((#\Newline #\Space) (PRIN-DEFAULT) (RESULT DEFAULT))
          (OTHERWISE (RETURN)))
        (EVENT-DISPATCH)))))