Created
August 2, 2010 22:32
-
-
Save ninjudd/505441 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/bin/cake b/bin/cake | |
index 09d9e9d..3f12f88 100755 | |
--- a/bin/cake | |
+++ b/bin/cake | |
@@ -407,9 +407,14 @@ private | |
end | |
def read_until_prompt(socket) | |
- while line = socket.gets | |
+ while ready = select([socket, $stdin])[0][0] | |
+ if ready == socket | |
+ line = socket.gets | |
return $1 if line =~ /^#{REPL_PROMPT}(.*)$/ | |
puts line | |
+ else | |
+ socket.puts($stdin.gets) | |
+ end | |
end | |
end | |
diff --git a/src/cake/server.clj b/src/cake/server.clj | |
index 1f84926..8e083ca 100644 | |
--- a/src/cake/server.clj | |
+++ b/src/cake/server.clj | |
@@ -18,7 +18,7 @@ | |
(defn validate-form [] | |
(println | |
- (try (read) | |
+ (try (while (not= ::EOF (read *in* false ::EOF))) | |
"valid" | |
(catch clojure.lang.LispReader$ReaderException e | |
(if (.contains (.getMessage e) "EOF") | |
@@ -50,12 +50,15 @@ | |
(exit) | |
(println "warning: refusing to quit because there are active connections"))) | |
+(defn- reset-in [] | |
+ (while (.ready *in*) (.read *in*))) | |
+ | |
(defn repl [] | |
(let [marker (read)] | |
(swap! num-connections inc) | |
(clojure.main/repl | |
:init #(in-ns 'user) | |
- :prompt #(println (str marker (ns-name *ns*)))) | |
+ :prompt #(do (reset-in) (println (str marker (ns-name *ns*))))) | |
(swap! num-connections dec))) | |
(defn eval-verbose [form] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment