Skip to content

Commit

Permalink
Turn off jline for stdin reads
Browse files Browse the repository at this point in the history
  • Loading branch information
trptcolin committed Feb 17, 2013
1 parent f81e53c commit bfb14b8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
16 changes: 8 additions & 8 deletions src/clj/reply/eval_modes/nrepl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@
(some #{"done" "interrupted" "error"} (:status %))))
(filter identity (session-responses session)))]
(when (some #{"need-input"} (:status res))
(let [input-result (safe-read-line {:input-stream *in*
:prompt-string (constantly "STDIN> ")})]
(when-not (= :interrupted input-result)
(session-sender
{:op "stdin" :stdin (str input-result "\n")
:id (nrepl.misc/uuid)}))))
(let [input-result (safe-read-line {:no-jline true
:prompt-string ""})]
(session-sender
{:op "stdin" :stdin (str input-result "\n")
:id (nrepl.misc/uuid)})))
(when value ((:value options print) value))
(flush)
(when (and ns (not (:session options)))
Expand All @@ -80,9 +79,10 @@
(reset! current-command-id nil)
@current-ns))

(defn parsed-forms [{:keys [ns request-exit text-so-far prompt-string] :as options}]
(defn parsed-forms [{:keys [ns request-exit text-so-far
prompt-string input-stream] :as options}]
(if-let [next-text (safe-read-line {:ns ns
:input-stream *in*
:input-stream input-stream
:prompt-string prompt-string})]
(let [interrupted? (= :interrupted next-text)
parse-tree (when-not interrupted?
Expand Down
1 change: 1 addition & 0 deletions src/clj/reply/reader/jline/completion.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
(defn make-completer [eval-fn redraw-line-fn ns]
(proxy [Completer] []
(complete [^String buffer cursor ^java.util.List candidates]
; candidates is empty, wants possibilities added
(let [buffer (or buffer "")
prefix (or (completion/get-word-ending-at buffer cursor) "")
prefix-length (.length prefix)
Expand Down
43 changes: 27 additions & 16 deletions src/clj/reply/reader/simple_jline.clj
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,43 @@
(.setPaginationEnabled true)
(.setPrompt prompt-string))))

(def jline-state (atom {}))

(defn get-input-line [state]
(if (:reader state)
(prepare-for-next-read state)
(initialize-jline))
(let [reader (setup-console-reader state)
input (try (.readLine reader)
(catch jline.console.UserInterruptException e
:interrupted))]
(if (= :interrupted input)
(assoc state
:reader reader
:input ""
:interrupted true)
(assoc state
:reader reader
:input input
:interrupted nil))))

(def jline-state (atom {}))
(if (:no-jline state)
(do
(shutdown state) ; TODO: this prints a newline; stop jline from doing this.
(assoc (dissoc state :no-jline)
:reader nil
:input (read-line)))
(let [reader (setup-console-reader state)
input (try (.readLine reader)
(catch jline.console.UserInterruptException e
:interrupted))]
(if (= :interrupted input)
(assoc state
:reader reader
:input ""
:interrupted true)
(assoc state
:reader reader
:input input
:interrupted nil)))))

(defn safe-read-line
[{:keys [input-stream prompt-string completer-factory] :as state}]
[{:keys [prompt-string completer-factory no-jline input-stream] :as options}]
(swap! jline-state
assoc
:no-jline no-jline
:prompt-string prompt-string
:completer-factory completer-factory)

(when input-stream ; default args are janky
(swap! jline-state assoc :input-stream input-stream))

(swap! jline-state
(fn [previous-state]
(get-input-line previous-state)))
Expand Down

0 comments on commit bfb14b8

Please sign in to comment.