(apply-input-event key))
(loop))))))
-(define (keyboard-peek-no-hang)
- (handle-simple-events (lambda () ((editor-peek-no-hang current-editor) 0))
- #t))
+(define (keyboard-peek-no-hang #!optional timeout)
+ (let ((milliseconds (if (default-object? timeout) 0 timeout)))
+ (guarantee-fixnum milliseconds 'keyboard-peek-no-hang)
+ (handle-simple-events-until
+ (+ (real-time-clock) milliseconds)
+ (editor-peek-no-hang current-editor)
+ #t)))
(define (handle-simple-events thunk discard?)
(let loop ()
(let ((input (thunk)))
- (if (and (input-event? input)
- (let ((type (input-event/type input)))
- (or (eq? type 'UPDATE)
- (eq? type 'SET-SCREEN-SIZE)
- (and (eq? type 'DELETE-SCREEN)
- (eq? (input-event/operator input) delete-screen!)
- (not (selected-screen?
- (car (input-event/operands input))))))))
- (begin
- (apply-input-event input)
- (if discard? ((editor-read current-editor)))
- (loop))
+ (if (simple-event-handled? input discard?)
+ (loop)
input))))
+
+(define (simple-event-handled? input discard?)
+ (if (and (input-event? input)
+ (let ((type (input-event/type input)))
+ (or (eq? type 'UPDATE)
+ (eq? type 'SET-SCREEN-SIZE)
+ (and (eq? type 'DELETE-SCREEN)
+ (eq? (input-event/operator input) delete-screen!)
+ (not (selected-screen?
+ (car (input-event/operands input))))))))
+ (begin
+ (apply-input-event input)
+ (if discard? ((editor-read current-editor)))
+ #t)
+ #f))
+
+(define (handle-simple-events-until end-time peek-no-hang discard?)
+ (let loop ()
+ (let* ((now (real-time-clock))
+ (timeout (- end-time now)))
+ (if (not (positive? timeout))
+ #f
+ (let ((input (peek-no-hang timeout)))
+ (if (simple-event-handled? input discard?)
+ (loop)
+ input))))))
\f
(define read-key-timeout/fast 500)
(define read-key-timeout/slow 2000)
(else (extract-string start end))))))))
(define (sit-for interval)
- (let ((time-limit (+ (real-time-clock) interval)))
- (let loop ()
- (if (and (not (keyboard-peek-no-hang))
- (< (real-time-clock) time-limit)
- (update-screens! false))
- (loop)))))
+ (guarantee-fixnum interval 'sit-for)
+ (update-screens! 'ignore-input)
+ (keyboard-peek-no-hang interval))
(define sleep-for
sleep-current-thread)