            [scala.tools.jline.console.history FileHistory]
            [java.io File]))
 
-; TODO: allow multi-line input
 (defn actual-read [input request-prompt request-exit]
-  (binding [*in* (clojure.lang.LineNumberingPushbackReader. (java.io.StringReader. input))]
+  (binding [*in* (clojure.lang.LineNumberingPushbackReader. input)]
     (clojure.main/repl-read request-prompt request-exit)))
 
 (def main-thread (Thread/currentThread))

(defn get-prompt [ns]
  (format "%s=> " (ns-name ns)))

(defn handle-ctrl-c [signal]
  (println "^C")
  (.interrupt main-thread)
  (-> (.getCursorBuffer jline-reader)
      (.clear))
  (print (get-prompt @current-repl-ns))
  (flush))

(defn jline-read [request-prompt request-exit]
  (try
    (.setPrompt jline-reader (get-prompt *ns*))
    (reset! current-repl-ns *ns*)
    (let [input (.readLine jline-reader)]
      (cond (not input)
              request-exit
            (every? #(Character/isWhitespace %) input)
              request-prompt
            :else
              (do
                (Thread/interrupted) ; just to clear the status
                (actual-read input request-prompt request-exit))))
    (catch InterruptedException e
      (-> (.getCursorBuffer jline-reader)
          (.clear))
      (request-prompt))))

(defn -main [& args]
  (set-break-handler! handle-ctrl-c)

  (repl :read jline-read
        :prompt (constantly ""))

  (shutdown-agents)

  (.flush (.getHistory jline-reader)))

