From 0ce1ee145e953ba138366316e270c1ba21f5ab97 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Thu, 12 Oct 2006 18:27:55 +0000 Subject: [PATCH] * Expose a prompt parameter for use with readline * Print the prompt if not currently repl-ing through the readline input svn: r4566 --- collects/readline/doc.txt | 3 +++ collects/readline/pread.ss | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/collects/readline/doc.txt b/collects/readline/doc.txt index 5aea7cc1b1..ebfd1b23e9 100644 --- a/collects/readline/doc.txt +++ b/collects/readline/doc.txt @@ -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 customized with these parameters: +> currnet-prompt + The prompt that is used, as a byte string. Defaults to #"> ". + > show-all-prompts If #f, no prompt is shown until you write input that is completely readable. For example, when you type diff --git a/collects/readline/pread.ss b/collects/readline/pread.ss index f6e29f53df..2259fc310e 100644 --- a/collects/readline/pread.ss +++ b/collects/readline/pread.ss @@ -2,11 +2,13 @@ (require (lib "readline.ss" "readline") (lib "file.ss")) ;; configuration + (define current-prompt (make-parameter #"> ")) (define show-all-prompts (make-parameter #t)) (define max-history (make-parameter 100)) (define keep-duplicates (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 @@ -132,9 +134,15 @@ ;; a function that can be used for current-prompt-read (provide read-cmdline-syntax) (define (read-cmdline-syntax) + (define prompt (current-prompt)) ;; needs to set `readline-prompt' to get a prompt when reading (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)))) )