 (ns nightcode.repl
   (:require [nightcode.editors :as editors]
             [nightcode.lein :as lein]
+            [nightcode.sandbox :as sandbox]
             [nightcode.shortcuts :as shortcuts]
             [nightcode.ui :as ui]
             [seesaw.core :as s]))

  "Starts a REPL process."
  [process in-out]
  (lein/stop-process! process)
  (->> (lein/start-process-indirectly! process nil "clojure.main")
       (lein/start-thread! in-out)))

(defn create-pane

  (let [process (atom nil)
        run! (fn [& _]
               (s/request-focus! (-> console .getViewport .getView))
               (run-repl! process (ui/get-io! console)))
        pane (s/config! console :id :repl-console)]
    ; start the repl
    (run!)
    ; create a shortcut to restart the repl
    (when-not (sandbox/get-dir)
      (shortcuts/create-hints! pane)
      (shortcuts/create-mappings! pane {:repl-console run!}))
    ; return the repl pane
    pane))
