* Expose a prompt parameter for use with readline

* Print the prompt if not currently repl-ing through the readline input

svn: r4566
This commit is contained in:
Eli Barzilay 2006-10-12 18:27:55 +00:00
parent a98abdc45f
commit 0ce1ee145e
2 changed files with 13 additions and 2 deletions

View File

@ -34,6 +34,9 @@ prompt-reading after "rep.ss" installs the new input port.
The reading facility that the new input port provides can be The reading facility that the new input port provides can be
customized with these parameters: customized with these parameters:
> currnet-prompt
The prompt that is used, as a byte string. Defaults to #"> ".
> show-all-prompts > show-all-prompts
If #f, no prompt is shown until you write input that is completely If #f, no prompt is shown until you write input that is completely
readable. For example, when you type readable. For example, when you type

View File

@ -2,11 +2,13 @@
(require (lib "readline.ss" "readline") (lib "file.ss")) (require (lib "readline.ss" "readline") (lib "file.ss"))
;; configuration ;; configuration
(define current-prompt (make-parameter #"> "))
(define show-all-prompts (make-parameter #t)) (define show-all-prompts (make-parameter #t))
(define max-history (make-parameter 100)) (define max-history (make-parameter 100))
(define keep-duplicates (make-parameter #f)) (define keep-duplicates (make-parameter #f))
(define keep-blanks (make-parameter #f)) (define keep-blanks (make-parameter #f))
(provide show-all-prompts max-history keep-duplicates keep-blanks) (provide current-prompt show-all-prompts
max-history keep-duplicates keep-blanks)
;; History management ;; History management
@ -132,9 +134,15 @@
;; a function that can be used for current-prompt-read ;; a function that can be used for current-prompt-read
(provide read-cmdline-syntax) (provide read-cmdline-syntax)
(define (read-cmdline-syntax) (define (read-cmdline-syntax)
(define prompt (current-prompt))
;; needs to set `readline-prompt' to get a prompt when reading ;; needs to set `readline-prompt' to get a prompt when reading
(parameterize ([read-accept-reader #t] (parameterize ([read-accept-reader #t]
[readline-prompt #"> "]) [readline-prompt prompt])
(unless (eq? readline-input (current-input-port))
;; not the readline port -- print the prompt (changing the
;; readline-prompt and using read-complete-syntax below should still
;; work fine)
(display prompt) (flush-output))
(if (show-all-prompts) (read-syntax) (read-complete-syntax)))) (if (show-all-prompts) (read-syntax) (read-complete-syntax))))
) )