Skip to content
Browse files

add rebel-readline to figwheel repl!

  • Loading branch information
Bruce Hauman
Bruce Hauman committed Feb 11, 2018
1 parent e12397c commit 55de952de19eb69e1f121f21f69d8b8a6fc0eda2
Showing with 42 additions and 1 deletion.
  1. +1 −0 plugin/project.clj
  2. +12 −0 plugin/src/leiningen/figwheel.clj
  3. +29 −1 sidecar/src/figwheel_sidecar/repl.clj
@@ -11,6 +11,7 @@
:dir ".."}

:profiles {:dev {:dependencies [[leiningen "2.7.1"]
[rebel-readline-cljs "0.1.0-SNAPSHOT"]
[org.clojure/test.check "0.9.0"]]
:source-paths ["dev" "src"]
:aliases {"change-version" ["run" "-m" "figwheel-tasks.core" ":change-version"]
@@ -11,6 +11,7 @@
[simple-lein-profile-merge.core :as lm]))

(def _figwheel-version_ "0.5.15-SNAPSHOT")
(def _rebel-readline-cljs-version_ "0.1.0-SNAPSHOT")

(defn make-subproject [project paths-to-add]
@@ -43,11 +44,22 @@
(System/exit 1))))

(defn coord-version [library]
(let [[_ coords version]
(some-> (io/resource (format "META-INF/leiningen/%s/%s/project.clj" library library))

(def rebel-readline-cljs-version
(or (coord-version "rebel-readline-cljs") _rebel-readline-cljs-version_))

;; well this is private in the leiningen.cljsbuild ns
(defn- run-local-project [project paths-to-add requires form]
(let [project' (-> project
(update-in [:dependencies] conj ['figwheel-sidecar _figwheel-version_])
(update-in [:dependencies] conj ['figwheel _figwheel-version_])
(update-in [:dependencies] conj ['rebel-readline-cljs rebel-readline-cljs-version])
(make-subproject paths-to-add))]
(eval-and-catch project' requires form)))

@@ -194,7 +194,35 @@ This can cause confusion when your are not using Cider."]

(defmethod start-cljs-repl :default
[_ figwheel-env]
(cljs.repl/repl* figwheel-env (:repl-opts figwheel-env)))
(let [prompt (:prompt (:repl-opts figwheel-env))
prompt-fn' (fn [] (with-out-str (prompt)))]
(cond (and
(require? 'rebel-readline.core)
(require? 'rebel-readline-cljs.service)
(require? 'rebel-readline-cljs.core)
(resolve 'rebel-readline.core/line-reader)
(resolve 'rebel-readline-cljs.service/create)
(resolve 'rebel-readline-cljs.core/cljs-repl-read))
(let [line-reader (resolve 'rebel-readline.core/line-reader)
cljs-service (resolve 'rebel-readline-cljs.service/create)
cljs-repl-read (resolve 'rebel-readline-cljs.core/cljs-repl-read)]
(:repl-opts figwheel-env)
:read (cljs-repl-read
(cljs-service {:repl-env figwheel-env
:prompt prompt-fn'})))
:prompt (fn [])))
(catch clojure.lang.ExceptionInfo e
(if (-> e ex-data :type (= :rebel-readline.line-reader/bad-terminal))
(do (println (.getMessage e))
(println "Falling back to REPL without terminal readline functionality!")
(cljs.repl/repl* figwheel-env (:repl-opts figwheel-env)))))))
(cljs.repl/repl* figwheel-env (:repl-opts figwheel-env)))))

(defn in-nrepl-env? []
(thread-bound? #'nrepl-eval/*msg*))

0 comments on commit 55de952

Please sign in to comment.
You can’t perform that action at this time.