Back
repl-read (clj)
(source)function
(repl-read request-prompt request-exit)
Default :read hook for repl. Reads from *in* which must either be an
instance of LineNumberingPushbackReader or duplicate its behavior of both
supporting .unread and collapsing all of CR, LF, and CRLF into a single
\newline. repl-read:
- skips whitespace, then
- returns request-prompt on start of line, or
- returns request-exit on end of stream, or
- reads an object from the input stream, then
- skips the next input character if it's end of line, then
- returns the object.
Examples
clojure/core.typed
(deftest demunge-test
(is-tc-e (demunge "abc") String
:requires [[clojure.main :refer [demunge]]])
(is-tc-err (demunge "abc") Boolean
:requires [[clojure.main :refer [demunge]]])
(is-tc-err (demunge 1) String
:requires [[clojure.main :refer [demunge]]]))
(deftest repl-test
(is-tc-e #(repl)
:requires [[clojure.main :refer [repl]]])
(is-tc-e #(repl :init (fn [])
:need-prompt (fn [] (identity true))
:flush flush
:read repl-read
:eval eval
:print prn
:caught repl-caught)
:requires [[clojure.main :refer [repl repl-read repl-caught]]]))
typedclojure/typedclojure
(deftest demunge-test
(is-tc-e (demunge "abc") String
:requires [[clojure.main :refer [demunge]]])
(is-tc-err (demunge "abc") Boolean
:requires [[clojure.main :refer [demunge]]])
(is-tc-err (demunge 1) String
:requires [[clojure.main :refer [demunge]]]))
(deftest repl-test
(is-tc-e #(repl)
:requires [[clojure.main :refer [repl]]])
(is-tc-e #(repl :init (fn [])
:need-prompt (fn [] (identity true))
:flush flush
:read repl-read
:eval eval
:print prn
:caught repl-caught)
:requires [[clojure.main :refer [repl repl-read repl-caught]]]))
funcool/beicon
(require '[clojure.java.shell :as shell])
(require '[rebel-readline.core]
'[rebel-readline.clojure.main]
'[rebel-readline.clojure.line-reader]
'[rebel-readline.clojure.service.local]
'[rebel-readline.cljs.service.local]
'[rebel-readline.cljs.repl])
(require '[cljs.build.api :as api]
'[cljs.repl :as repl]
'[cljs.repl.node :as node])
(defmethod task "repl:jvm"
[args]
(rebel-readline.core/with-line-reader
(rebel-readline.clojure.line-reader/create
(rebel-readline.clojure.service.local/create))
(clojure.main/repl
:prompt (fn []) ;; prompt is handled by line-reader
:read (rebel-readline.clojure.main/create-repl-read))))
(defmethod task "repl:node"
[args]
(rebel-readline.core/with-line-reader
(rebel-readline.clojure.line-reader/create
(rebel-readline.cljs.service.local/create))
(cljs.repl/repl
(node/repl-env)
:prompt (fn []) ;; prompt is handled by line-reader
:read (rebel-readline.cljs.repl/create-repl-read)
:output-dir "out"
:cache-analysis false)))
funcool/struct
(require '[clojure.java.shell :as shell]
'[clojure.main])
(require '[rebel-readline.core]
'[rebel-readline.clojure.main]
'[rebel-readline.clojure.line-reader]
'[rebel-readline.clojure.service.local]
'[rebel-readline.cljs.service.local]
'[rebel-readline.cljs.repl]
'[eftest.runner :as ef])
(require '[cljs.build.api :as api]
'[cljs.repl :as repl]
'[cljs.repl.node :as node])
(defmethod task "repl"
[[_ type]]
(case type
(nil "clj")
(rebel-readline.core/with-line-reader
(rebel-readline.clojure.line-reader/create
(rebel-readline.clojure.service.local/create))
(clojure.main/repl
:prompt (fn []) ;; prompt is handled by line-reader
:read (rebel-readline.clojure.main/create-repl-read)))
"node"
(rebel-readline.core/with-line-reader
(rebel-readline.clojure.line-reader/create (rebel-readline.cljs.service.local/create))
(cljs.repl/repl
(node/repl-env)
:prompt (fn []) ;; prompt is handled by line-reader
:read (rebel-readline.cljs.repl/create-repl-read)
:output-dir "out"
:cache-analysis false))
(println "Unknown repl: " type)
(System/exit 1)))
funcool/lentes
(require '[rebel-readline.core]
'[rebel-readline.clojure.main]
'[rebel-readline.clojure.line-reader]
'[rebel-readline.clojure.service.local]
'[rebel-readline.cljs.service.local]
'[rebel-readline.cljs.repl])
(defmethod task "repl:jvm"
[args]
(rebel-readline.core/with-line-reader
(rebel-readline.clojure.line-reader/create
(rebel-readline.clojure.service.local/create))
(clojure.main/repl
:prompt (fn []) ;; prompt is handled by line-reader
:read (rebel-readline.clojure.main/create-repl-read))))
(defmethod task "repl:node"
[args]
(rebel-readline.core/with-line-reader
(rebel-readline.clojure.line-reader/create
(rebel-readline.cljs.service.local/create))
(cljs.repl/repl
(node/repl-env)
:prompt (fn []) ;; prompt is handled by line-reader
:read (rebel-readline.cljs.repl/create-repl-read)
:output-dir "out"
:cache-analysis false)))