allowing configurable prompts (patch from Alan Watson)

This commit is contained in:
Alex Shinn 2012-07-10 20:45:13 +09:00
parent a2c5d63482
commit 0c832129df

View file

@ -84,6 +84,7 @@
;;> @item{@scheme{out:} - the output port (default @scheme{(current-output-port)})} ;;> @item{@scheme{out:} - the output port (default @scheme{(current-output-port)})}
;;> @item{@scheme{module:} - the initial module (default @scheme{(interaction-environment)})} ;;> @item{@scheme{module:} - the initial module (default @scheme{(interaction-environment)})}
;;> @item{@scheme{escape:} - the command escape character (default @scheme|{#\@}|)} ;;> @item{@scheme{escape:} - the command escape character (default @scheme|{#\@}|)}
;;> @item{@scheme{make-prompt:} - a procedure taking one argument (the current module name as a list) and returning a string to be used as the prompt}
;;> @item{@scheme{history:} - the initial command history} ;;> @item{@scheme{history:} - the initial command history}
;;> @item{@scheme{history-file:} - the file to save history to (default ~/.chibi-repl-history)} ;;> @item{@scheme{history-file:} - the file to save history to (default ~/.chibi-repl-history)}
;;> ] ;;> ]
@ -112,6 +113,12 @@
(module-env (module-env
(if (module? module) module (load-module module))) (if (module? module) module (load-module module)))
(interaction-environment))) (interaction-environment)))
(make-prompt
(cond
((memq 'make-prompt: o) => cadr)
(else
(lambda (module)
(string-append (if module (write-to-string module) "") "> ")))))
(history-file (history-file
(cond ((memq 'history-file: o) => cadr) (cond ((memq 'history-file: o) => cadr)
(else (string-append (get-environment-variable "HOME") (else (string-append (get-environment-variable "HOME")
@ -129,8 +136,7 @@
(let lp ((module module) (let lp ((module module)
(env env) (env env)
(meta-env (module-env (load-module '(meta))))) (meta-env (module-env (load-module '(meta)))))
(let* ((prompt (let* ((prompt (make-prompt module))
(string-append (if module (write-to-string module) "") "> "))
(line (line
(cond (cond
(raw? (raw?