Skip to content

Commit 0a0ff32

Browse files
mfikesswannodette
authored andcommitted
CLJS-2897: cljs.main: Display initial REPL prompt sooner
1 parent 1a155ad commit 0a0ff32

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/main/clojure/cljs/cli.clj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ is trying load some arbitrary ns."
289289
(util/mkdirs f)
290290
(util/path f)))
291291

292+
(defn- repl-name [repl-env]
293+
(subs (-> repl-env meta :ns str) (count "cljs.repl.")))
294+
295+
(defn- fast-initial-prompt? [repl-env inits]
296+
(and (empty? inits)
297+
(contains? #{"node" "nashorn" "graaljs" "rhino"} (repl-name repl-env))))
298+
292299
(defn- repl-opt
293300
"Start a repl with args and inits. Print greeting if no eval options were
294301
present"
@@ -304,6 +311,7 @@ present"
304311
renv (apply repl-env (mapcat identity reopts))]
305312
(repl/repl* renv
306313
(assoc (dissoc-entry-point-opts opts)
314+
::repl/fast-initial-prompt? (fast-initial-prompt? repl-env inits)
307315
:inits
308316
(into
309317
[{:type :init-forms

src/main/clojure/cljs/repl.cljc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -853,13 +853,19 @@
853853
(cljsc/maybe-install-node-deps! opts)
854854
installed?)))))
855855

856+
(defn initial-prompt [quit-prompt prompt]
857+
(quit-prompt)
858+
(prompt)
859+
(flush))
860+
856861
(defn repl*
857862
[repl-env {:keys [init inits need-prompt quit-prompt prompt flush read eval print caught reader
858-
print-no-newline source-map-inline wrap repl-requires
863+
print-no-newline source-map-inline wrap repl-requires ::fast-initial-prompt?
859864
compiler-env bind-err]
860865
:or {need-prompt #(if (readers/indexing-reader? *in*)
861866
(== (readers/get-column-number *in*) 1)
862867
(identity true))
868+
fast-initial-prompt? false
863869
quit-prompt repl-title
864870
prompt repl-prompt
865871
flush flush
@@ -879,6 +885,8 @@
879885
(doseq [[unknown-opt suggested-opt] (util/unknown-opts (set (keys opts)) (set/union known-repl-opts cljsc/known-opts))]
880886
(when suggested-opt
881887
(println (str "WARNING: Unknown option '" unknown-opt "'. Did you mean '" suggested-opt "'?"))))
888+
(when fast-initial-prompt?
889+
(initial-prompt quit-prompt prompt))
882890
(let [repl-opts (-repl-options repl-env)
883891
repl-requires (into repl-requires (:repl-requires repl-opts))
884892
{:keys [analyze-path repl-verbose warn-on-undeclared special-fns
@@ -1010,9 +1018,8 @@
10101018
(binding [*in* (if (true? (:source-map-inline opts))
10111019
*in*
10121020
(reader))]
1013-
(quit-prompt)
1014-
(prompt)
1015-
(flush)
1021+
(when-not fast-initial-prompt?
1022+
(initial-prompt quit-prompt prompt))
10161023
(loop []
10171024
(when-not
10181025
(try

0 commit comments

Comments
 (0)