   (:import cljs.repl.IJavaScriptEnv
            java.net.Socket
            java.lang.StringBuilder
-           [java.io BufferedReader BufferedWriter]))
+           [java.io BufferedReader BufferedWriter]
+           [java.lang ProcessBuilder UNIXProcess ProcessBuilder$Redirect]))
 
 (defn socket [host port]
   (let [socket (Socket. host port)

               (.append sb (char c))
               (recur sb (.read in)))))))

(defn node-eval [{{:keys [in out]} :socket :as repl-env} js]
  (write out js)
  {:status :success :value (read-response in)})

(defn load-javascript [repl-env ns url]
  (node-eval repl-env (slurp url)))

(defn setup [repl-env]
  (let [env (ana/empty-env)]
    (repl/load-file repl-env "cljs/core.cljs")
    (swap! (:loaded-libs repl-env) conj "cljs.core")
    (repl/evaluate-form repl-env
      env "<cljs repl>"
      '(ns cljs.user))
    (repl/evaluate-form repl-env
      env "<cljs repl>"
      '(set! *print-fn* (fn [x] (js/node_repl_print (pr-str x)))))))

(defrecord NodeEnv [socket loaded-libs]
  repl/IJavaScriptEnv
  (-setup [this]
    (setup this))

    (close-socket socket)))

(defn repl-env* [{:keys [host port] :or {host "localhost" port 5001}}]
  (NodeEnv. host port (atom nil) (atom {})))

(defn repl-env
  [& options]
  (repl-env* options))

(comment

  (def bldr (ProcessBuilder. (into-array ["node"])))


  )