first commit

This commit is contained in:
frese 2004-09-15 14:49:54 +00:00
parent 5921374d20
commit 03d7ee90f6
1 changed files with 37 additions and 0 deletions

examples/timed-choice.scm Executable file
View File

@ -0,0 +1,37 @@
exec scsh -lel expect/load.scm -o expect -o srfi-13 -e main -s "$0" "$@"
(define (display-usage)
(display "Usage: timed-choice.scm timeout query choices...\n")
(display "Provides a query of the user with a timeout and a default answer.\n"))
(define (raise-too-few-arguments)
(display "timed-choice.scm: too few arguments\n")
(define (main args)
(if (< (length args) 4)
(let ((timeout (string->number (second args)))
(query (third args))
(choices (cdddr args)))
(let ((default (car choices))
(pattern (re-choice (map re-string choices))))
(display (format #f "~a [~a] " query (string-join choices ", ")))
(expect loop ()
(option (timeout timeout)
(on-timeout default))
((rx (: bos ,pattern (| "\n" "\r\n"))) (m)
(match:substring m))
((rx (: bos (| "\n" "\r\n"))) ()
(string-append default "\n"))
(display (format #f "Please enter one of the choices: ~a.\n"
(string-join choices ", ")))