How to change Janet's REPL prompt? #1368
-
When I start
I'm wondering how I can change it. I expected that it was defined somewhere in shell.c but it's not. Actually, it's defined in the function Of course, I could change this function in the Janet source code and rebuild the project. But as this is a Janet function, I guess it should be possible to change it without recompiling. I have tried to copy Is it possible at all to change the prompt at run-time? (I'm not asking because I need a different prompt so much but because I want to learn about Janet.) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 10 replies
-
I also tried to rename repl:1:> (set ((env-lookup (curenv)) 'cli-main) cli-main-new)
<function cli-main-new> But still no effect. Another try without luck: repl:2:> (def cli-main cli-main-new) |
Beta Was this translation helpful? Give feedback.
-
This has been something I've wanted a nice way for as well but I haven't had much success. May be someone else has though (^^; Some not-so-satisfactory approaches that I've used include:
I hadn't tried your profile-based approach, may be I'll investigate that a bit. [1] See this file for the modifications to pieces of |
Beta Was this translation helpful? Give feedback.
-
As a follow-up, to remove the "sub-prompts" (the prompts that hint about unclosed delimiters), I tried the following sort of thing (mildly adapting part of what is expressed in (def env (make-env))
(defn my-get-prompt
[p]
(def [line] (parser/where p))
(if (empty? (parser/state p :delimiters))
(string "repl:" line ":" "> ")
""))
(defn my-getstdin [prompt buf _]
(file/write stdout prompt)
(file/flush stdout)
(file/read stdin :line buf))
(defn my-getchunk
[buf p]
# getline may not do what you want in some contexts (e.g. within emacs)
(my-getstdin (my-get-prompt p) buf env))
(repl my-getchunk nil env) What this might be useful for is in the context of editor tooling that might not want to be exposed to the aforementioned subprompts. I plugged it into ajrepl and it seems to be working so far in limited testing. |
Beta Was this translation helpful? Give feedback.
-
Possibly of interest might be the recent addition of |
Beta Was this translation helpful? Give feedback.
Possibly of interest might be the recent addition of
*repl-prompt*
. See here for a relevant commit.