Skip to content

Commit

Permalink
Handle interrupts properly in the latest jline
Browse files Browse the repository at this point in the history
Multiline forms now can be killed mid-form without closing them. No more
printing "^C" and not actually killing the input line!
  • Loading branch information
trptcolin committed Feb 3, 2013
1 parent ef1e5af commit b75f5f1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(defproject reply "0.1.10-SNAPSHOT"
:description "REPL-y: A fitter, happier, more productive REPL for Clojure."
:dependencies [[org.clojure/clojure "1.4.0"]
[jline/jline "2.8"]
[jline/jline "2.10"]
[org.thnetos/cd-client "0.3.6"]
[clj-stacktrace "0.2.4"]
[org.clojure/tools.nrepl "0.2.1"]
Expand Down
26 changes: 17 additions & 9 deletions src/clj/reply/eval_modes/nrepl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
TimeUnit/MILLISECONDS)
(session-responses session))))

(defn safe-read-line [input-stream]
(try (.readLine input-stream)
(catch jline.console.UserInterruptException e
:interrupted)))

(defn execute-with-client [client options form]
(let [command-id (nrepl.misc/uuid)
session (or (:session options) @current-session)
Expand All @@ -50,10 +55,11 @@
(some #{"done" "interrupted" "error"} (:status %))))
(filter identity (session-responses session)))]
(when (some #{"need-input"} (:status res))
(let [input-result (.readLine *in*)]
(session-sender
{:op "stdin" :stdin (str input-result "\n")
:id (nrepl.misc/uuid)})))
(let [input-result (safe-read-line *in*)]
(when-not (= :interrupted input-result)
(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 @@ -65,12 +71,14 @@
(defn parsed-forms
([request-exit] (parsed-forms request-exit nil))
([request-exit text-so-far]
(if-let [next-text (.readLine *in*)]
(let [concatted-text (if text-so-far
(if-let [next-text (safe-read-line *in*)]
(let [interrupted? (= :interrupted next-text)
parse-tree (when-not interrupted?
(sjacket.parser/parser
(if text-so-far
(str text-so-far \newline next-text)
next-text)
parse-tree (sjacket.parser/parser concatted-text)]
(if (empty? (:content parse-tree))
next-text)))]
(if (or interrupted? (empty? (:content parse-tree)))
(list "")
(let [completed? (fn [node]
(or (not= :net.cgrand.parsley/unfinished (:tag node))
Expand Down
1 change: 1 addition & 0 deletions src/clj/reply/reader/jline.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
history (FileHistory. (make-history-file (:history-file options)))
completer (jline.completion/make-completer reply.initialization/eval-in-user-ns #())]
(.setBlinkMatchingParen (.getKeys reader) true)
(.setHandleUserInterrupt reader true)
(doto reader
(.setHistory history)
(.setExpandEvents false)
Expand Down

0 comments on commit b75f5f1

Please sign in to comment.