Permalink
Browse files

Handle interrupts properly in the latest jline

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...
1 parent ef1e5af commit b75f5f109e872a12e86ac92bbe4d60f4669e0781 @trptcolin committed Feb 3, 2013
Showing with 19 additions and 10 deletions.
  1. +1 −1 project.clj
  2. +17 −9 src/clj/reply/eval_modes/nrepl.clj
  3. +1 −0 src/clj/reply/reader/jline.clj
View
2 project.clj
@@ -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"]
View
26 src/clj/reply/eval_modes/nrepl.clj
@@ -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)
@@ -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)))
@@ -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))
View
1 src/clj/reply/reader/jline.clj
@@ -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)

0 comments on commit b75f5f1

Please sign in to comment.