mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 15:43:01 +00:00 
			
		
		
		
	Add *repl-prompt*.
This commit is contained in:
		| @@ -2,6 +2,8 @@ | |||||||
| All notable changes to this project will be documented in this file. | All notable changes to this project will be documented in this file. | ||||||
|  |  | ||||||
| ## ??? - Unreleased | ## ??? - Unreleased | ||||||
|  | - Change how JANET_PROFILE is loaded to allow more easily customizing the environment. | ||||||
|  | - Add `*repl-prompt*` dynamic binding to allow customizing the built in repl. | ||||||
| - Add multiple path support in the `JANET_PATH` environment variables. This lets | - Add multiple path support in the `JANET_PATH` environment variables. This lets | ||||||
|   user more easily import modules from many directories. |   user more easily import modules from many directories. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1853,6 +1853,9 @@ | |||||||
| (defdyn *pretty-format* | (defdyn *pretty-format* | ||||||
|   "Format specifier for the `pp` function") |   "Format specifier for the `pp` function") | ||||||
|  |  | ||||||
|  | (defdyn *repl-prompt* | ||||||
|  |   "Allow setting a custom prompt at the default REPL. Not all REPLs will respect this binding.") | ||||||
|  |  | ||||||
| (defn pp | (defn pp | ||||||
|   ``Pretty-print to stdout or `(dyn *out*)`. The format string used is `(dyn *pretty-format* "%q")`.`` |   ``Pretty-print to stdout or `(dyn *out*)`. The format string used is `(dyn *pretty-format* "%q")`.`` | ||||||
|   [x] |   [x] | ||||||
| @@ -4643,17 +4646,15 @@ | |||||||
|         (if-not quiet |         (if-not quiet | ||||||
|           (print "Janet " janet/version "-" janet/build " " (os/which) "/" (os/arch) "/" (os/compiler) " - '(doc)' for help")) |           (print "Janet " janet/version "-" janet/build " " (os/which) "/" (os/arch) "/" (os/compiler) " - '(doc)' for help")) | ||||||
|         (flush) |         (flush) | ||||||
|  |         (def env (make-env)) | ||||||
|         (defn getprompt [p] |         (defn getprompt [p] | ||||||
|  |           (when-let [custom-prompt (get env *repl-prompt*)] (break (custom-prompt p))) | ||||||
|           (def [line] (parser/where p)) |           (def [line] (parser/where p)) | ||||||
|           (string "repl:" line ":" (parser/state p :delimiters) "> ")) |           (string "repl:" line ":" (parser/state p :delimiters) "> ")) | ||||||
|         (defn getstdin [prompt buf _] |         (defn getstdin [prompt buf _] | ||||||
|           (file/write stdout prompt) |           (file/write stdout prompt) | ||||||
|           (file/flush stdout) |           (file/flush stdout) | ||||||
|           (file/read stdin :line buf)) |           (file/read stdin :line buf)) | ||||||
|         (def env (make-env)) |  | ||||||
|         (when-let [profile.janet (dyn *profilepath*)] |  | ||||||
|           (def new-env (dofile profile.janet :exit true)) |  | ||||||
|           (merge-module env new-env "" false)) |  | ||||||
|         (when debug-flag |         (when debug-flag | ||||||
|           (put env *debug* true) |           (put env *debug* true) | ||||||
|           (put env *redef* true)) |           (put env *redef* true)) | ||||||
| @@ -4665,6 +4666,8 @@ | |||||||
|         (setdyn *doc-color* (if colorize true)) |         (setdyn *doc-color* (if colorize true)) | ||||||
|         (setdyn *lint-error* error-level) |         (setdyn *lint-error* error-level) | ||||||
|         (setdyn *lint-warn* error-level) |         (setdyn *lint-warn* error-level) | ||||||
|  |         (when-let [profile.janet (dyn *profilepath*)] | ||||||
|  |           (dofile profile.janet :exit true :env env)) | ||||||
|         (repl getchunk nil env))))) |         (repl getchunk nil env))))) | ||||||
|  |  | ||||||
| ### | ### | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose