Permalink
Browse files

Use a more-generic setInterruptFunction instead of setREPLThread

  • Loading branch information...
1 parent 6294688 commit 215aaa875563633c9ea877bf9ce19b0aed829d3e @ivan ivan committed Apr 24, 2012
Showing with 12 additions and 14 deletions.
  1. +6 −4 src/clj/org/dipert/swingrepl/main.clj
  2. +6 −10 src/jvm/bsh/util/JConsole.java
@@ -47,8 +47,9 @@
(.pack)
(.setSize width height))
(.requestFocus console)
- (let [thread (make-repl-thread console :init set-defaults!)]
- (.setREPLThread console thread)
+ (let [thread (make-repl-thread console :init set-defaults!)
+ stopper (clojure.repl/thread-stopper thread)]
+ (.setInterruptFunction console (fn [reason] (stopper reason)))
(.start thread)
(.setVisible jframe true))))))
@@ -104,8 +105,9 @@
(.requestFocus console#)
(let [thread (make-repl-thread console
:prompt #(print "dr => ")
- :eval (partial eval-with-locals (local-bindings)))]
- (.setREPLThread console thread)
+ :eval (partial eval-with-locals (local-bindings)))
+ stopper (clojure.repl/thread-stopper thread)]
+ (.setInterruptFunction console (fn [reason] (stopper reason)))
(.start thread)
(.setVisible jframe# true))))))
@@ -45,6 +45,7 @@
import java.awt.Cursor;
import javax.swing.text.*;
import javax.swing.*;
+import clojure.lang.IFn;
// Things that are not in the core packages
@@ -67,7 +68,7 @@
private final static String COPY = "Copy";
private final static String PASTE = "Paste";
- private Thread replThread;
+ private IFn interruptFunction;
private Writer outPipe;
private Reader inPipe;
private Reader in;
@@ -169,13 +170,8 @@ public void paste() {
requestFocus();
}
- public void setREPLThread(Thread replThread) {
- this.replThread = replThread;
- }
-
- @SuppressWarnings("deprecation")
- private void stopREPLThread() {
- this.replThread.stop(new Error("User pressed Ctrl-C"));
+ public void setInterruptFunction(IFn interruptFunction) {
+ this.interruptFunction = interruptFunction;
}
public void requestFocus() {
@@ -313,8 +309,8 @@ private synchronized void type(KeyEvent e) {
if (((e.getModifiers() & InputEvent.CTRL_MASK) > 0)
&& (e.getID() == KeyEvent.KEY_PRESSED)) {
//append("^C");
- if(replThread != null) {
- stopREPLThread();
+ if(interruptFunction != null) {
+ interruptFunction.invoke("User pressed Ctrl-C");
}
}
e.consume();

0 comments on commit 215aaa8

Please sign in to comment.