Skip to content

Commit

Permalink
add kaorahi fix for 717
Browse files Browse the repository at this point in the history
  • Loading branch information
featurecat committed Jun 7, 2020
1 parent 3bbde1d commit 68784e5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/featurecat/lizzie/gui/GtpConsolePane.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.Element;
import javax.swing.text.ElementIterator;
import javax.swing.text.StyleConstants;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.StyleSheet;
import org.json.JSONArray;
Expand All @@ -37,6 +41,7 @@ public class GtpConsolePane extends JDialog {
private final JTextField txtCommand = new JTextField();
private JLabel lblCommand = new JLabel();
private JPanel pnlCommand = new JPanel();
private final int MAX_HTML_LENGTH = 10000;

/** Creates a Gtp Console Window */
public GtpConsolePane(Window owner) {
Expand Down Expand Up @@ -124,12 +129,28 @@ public void addZenCommand(String command, int commandNumber) {
private void addText(String text) {
try {
htmlKit.insertHTML(htmlDoc, htmlDoc.getLength(), text, 0, 0, null);
removeOldText();
console.setCaretPosition(htmlDoc.getLength());
} catch (BadLocationException | IOException e) {
e.printStackTrace();
}
}

private void removeOldText() {
Element body =
htmlDoc.getElement(
htmlDoc.getDefaultRootElement(), StyleConstants.NameAttribute, HTML.Tag.BODY);
while (htmlDoc.getLength() > MAX_HTML_LENGTH) {
ElementIterator it = new ElementIterator(body);
it.first();
Element e = it.next();
if (e == null) {
break;
}
htmlDoc.removeElement(e);
}
}

public String formatZenCommand(String command, int commandNumber) {
return String.format(
"<span class=\"command\">" + ("YAZenGtp") + "> %d %s </span><br />",
Expand Down

0 comments on commit 68784e5

Please sign in to comment.