Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#14 - Have the ability to kill a repl command that is spewing data to the repl window #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@
(.setSelected (.printStackTraceToggleButton repl-pane) bv)
(.setSelected (.stackTraceOnErrorMenu repl-pane) bv)))

(defn interrupt-repl [repl-id]
((:repl-fn (org.enclojure.ide.repl.repl-manager/get-repl-config repl-id)) ":INTERRUPT"))

(defn check-repl-form?
([expr repl-id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
<Group type="102" alignment="0" attributes="0">
<Component id="replTooBar" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jTabbedPane1" pref="524" max="32767" attributes="0"/>
<Component id="jTabbedPane1" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jTabbedPane1" alignment="0" pref="177" max="32767" attributes="0"/>
<Component id="replTooBar" alignment="0" pref="177" max="32767" attributes="0"/>
<Component id="jTabbedPane1" alignment="0" pref="219" max="32767" attributes="0"/>
<Component id="replTooBar" alignment="0" pref="219" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
Expand Down Expand Up @@ -207,6 +207,21 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="replResetButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="replInterruptButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/org/enclojure/ide/resources/interrupt.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Interrupt Processing"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="label" type="java.lang.String" value=""/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="replInterruptButtonActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
*/
public class ReplPanel extends javax.swing.JPanel {
public int _promptPos = 0;
volatile IFn _interruptReplFn = (IFn)RT.var("org.enclojure.ide.repl.repl-panel", "interrupt-repl");
volatile IFn _evaluateInReplFn = (IFn)RT.var("org.enclojure.ide.repl.repl-panel", "evaluate-in-repl");
volatile IFn _processKeyEventFunc = (IFn)RT.var("org.enclojure.ide.repl.repl-panel", "process-key-input");
volatile IFn _dispShowHistoryEventsFunc = (IFn)RT.var("org.enclojure.ide.repl.repl-panel", "show-repl-history");
Expand Down Expand Up @@ -387,6 +388,7 @@ private void initComponents() {
clearReplHistoryButton = new javax.swing.JButton();
replStartupSettingsButton = new javax.swing.JButton();
replResetButton = new javax.swing.JButton();
replInterruptButton = new javax.swing.JButton();

jToolBar1.setRollover(true);

Expand Down Expand Up @@ -493,19 +495,32 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
});
replTooBar.add(replResetButton);

replInterruptButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/enclojure/ide/resources/interrupt.png"))); // NOI18N
replInterruptButton.setToolTipText("Interrupt Processing");
replInterruptButton.setFocusable(false);
replInterruptButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
replInterruptButton.setLabel("");
replInterruptButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
replInterruptButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
replInterruptButtonActionPerformed(evt);
}
});
replTooBar.add(replInterruptButton);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(replTooBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE))
.addComponent(jTabbedPane1))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
.addComponent(replTooBar, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
.addComponent(replTooBar, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents

Expand Down Expand Up @@ -545,6 +560,17 @@ private void clearReplHistoryButtonActionPerformed(java.awt.event.ActionEvent ev
clearReplHistoryActionPerformed(evt);
}//GEN-LAST:event_clearReplHistoryButtonActionPerformed

private void replInterruptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_replInterruptButtonActionPerformed
try
{
_interruptReplFn.invoke(this._replID);
}
catch (Exception ex)
{
Logger.getLogger(ReplPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_replInterruptButtonActionPerformed


// Variables declaration - do not modify//GEN-BEGIN:variables
public javax.swing.JEditorPane _replErrorPane;
Expand All @@ -559,6 +585,7 @@ private void clearReplHistoryButtonActionPerformed(java.awt.event.ActionEvent ev
public javax.swing.JButton printStackTraceButton;
public javax.swing.JToggleButton printStackTraceToggleButton;
public javax.swing.JButton replHistoryButton;
public javax.swing.JButton replInterruptButton;
public javax.swing.JButton replResetButton;
public javax.swing.JButton replStartupSettingsButton;
public javax.swing.JToolBar replTooBar;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
(:refer-clojure :exclude (with-bindings))
(:use clojure.contrib.pprint)
(:require [clojure.contrib.pprint :as pprint]
[clojure.main :exclude (with-binding)])
[clojure.main :exclude (with-binding)]
[clojure.contrib.repl-utils :as repl-utils])
(:import (java.net Socket ServerSocket)
(java.util.logging Level Logger)
(java.io InputStreamReader DataOutputStream DataInputStream
Expand Down Expand Up @@ -128,6 +129,7 @@
*out* piped-out
*err* (PrintWriter. *out*)]
(try
(repl-utils/add-break-thread!)
(clojure.main/repl
:init (fn [] (in-ns 'user))
:read (fn [prompt exit]
Expand All @@ -153,13 +155,11 @@
(catch java.nio.channels.ClosedByInterruptException ex)))]
(.start (Thread. repl-thread-fn))
{:repl-fn (fn [cmd]
(if (= cmd ":CLOSE-REPL")
(do
(.close cmd-wtr)
(.close result-rdr))
(do
(.write cmd-wtr cmd)
(.flush cmd-wtr))))
(cond
(= cmd ":INTERRUPT") (sun.misc.Signal/raise (sun.misc.Signal. "INT"))
(= cmd ":CLOSE-REPL") (do (.close cmd-wtr) (.close result-rdr))
:else (do (.write cmd-wtr cmd) (.flush cmd-wtr))))

;//??Using CharArrayWriter to build the string from each read of one byte
;Once there is nothing to read than this function returns the string read.
;Using partial so that CharArrayWriter is only created once and reused.
Expand Down