Skip to content

Commit

Permalink
Color code support, functional side panel
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwohara committed Jun 7, 2021
1 parent e0fb18c commit 2d683cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/irc/IrcPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void init()
{
panel.removeAll();

label.setText("<html><table width=230 style=\"word-wrap:break-word;\"></table></html>");
label.setText("<html><body style=\"width:180px;overflow:hidden;\"></body></html>");

panel.add(label);

Expand All @@ -34,11 +34,11 @@ private static void addMessage(String message)
{
panel.removeAll();

String existingMessages = label.getText().replace("</table></html>", "");
String existingMessages = label.getText().replace("</body></html>", "");

label.setText(existingMessages + "<tr><td>" + message + "</td></tr></table></html>");
message = message.replaceAll("(http[^ ]+)", "<a href=\"$1\" alt=\"$1\">link</a>");

log.warn(label.getText());
label.setText(existingMessages + "<div style=\"width:180px;word-wrap:break-word;overflow:hidden;\">" + message + "</div></body></html>");

panel.add(label);
}
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/com/irc/IrcPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,34 +200,34 @@ private void addChatMessage(String sender, String message)
.build());
}

IrcPanel.message(sender + " " + formatColors(message));
IrcPanel.message(formatColors(sender + ": " + message));
}

private String stripColors(String message)
{
return message.replaceAll("\u0003([0-9]{1,2})?", "");
return message.replaceAll("\u0003([0-9]{1,2})?|\u0015", "");
}

private String formatColors(String message)
{
return escapeHtml4(message)
.replaceAll("\u0003[^0-9]", "</font>")
.replaceAll("\u000310([^\u0003]+)", "<font color=\"darkcyan\">$1</font>")
.replaceAll("\u000311([^\u0003]+)", "<font color=\"cyan\">$1</font>")
.replaceAll("\u000312([^\u0003]+)", "<font color=\"blue\">$1</font>")
.replaceAll("\u000313([^\u0003]+)", "<font color=\"pink\">$1</font>")
.replaceAll("\u000314([^\u0003]+)", "<font color=\"grey\">$1</font>")
.replaceAll("\u000315([^\u0003]+)", "<font color=\"lightgrey`\">$1</font>")
.replaceAll("\u00030?1([^\u0003]+)", "<font color=\"black\">$1</font>")
.replaceAll("\u00030?2([^\u0003]+)", "<font color=\"darkblue\">$1</font>")
.replaceAll("\u00030?3([^\u0003]+)", "<font color=\"green\">$1</font>")
.replaceAll("\u00030?4([^\u0003]+)", "<font color=\"red\">$1</font>")
.replaceAll("\u00030?5([^\u0003]+)", "<font color=\"brown\">$1</font>")
.replaceAll("\u00030?6([^\u0003]+)", "<font color=\"purple\">$1</font>")
.replaceAll("\u00030?7([^\u0003]+)", "<font color=\"orange\">$1</font>")
.replaceAll("\u00030?8([^\u0003]+)", "<font color=\"yellow\">$1</font>")
.replaceAll("\u00030?9([^\u0003]+)", "<font color=\"chartreuse\">$1</font>")
.replaceAll("\u000300?([^\u0003]+)", "<font color=\"white\">$1</font>");
.replaceAll("[\u000F\u0003]([^0-9]|$)", "</font>$1")
.replaceAll("\u000310([^\u0003\u000F]+)", "<font color=\"darkcyan\">$1</font>")
.replaceAll("\u000311([^\u0003\u000F]+)", "<font color=\"cyan\">$1</font>")
.replaceAll("\u000312([^\u0003\u000F]+)", "<font color=\"blue\">$1</font>")
.replaceAll("\u000313([^\u0003\u000F]+)", "<font color=\"pink\">$1</font>")
.replaceAll("\u000314([^\u0003\u000F]+)", "<font color=\"grey\">$1</font>")
.replaceAll("\u000315([^\u0003\u000F]+)", "<font color=\"lightgrey`\">$1</font>")
.replaceAll("\u00030?1([^\u0003\u000F]+)", "<font color=\"black\">$1</font>")
.replaceAll("\u00030?2([^\u0003\u000F]+)", "<font color=\"darkblue\">$1</font>")
.replaceAll("\u00030?3([^\u0003\u000F]+)", "<font color=\"green\">$1</font>")
.replaceAll("\u00030?4([^\u0003\u000F]+)", "<font color=\"red\">$1</font>")
.replaceAll("\u00030?5([^\u0003\u000F]+)", "<font color=\"brown\">$1</font>")
.replaceAll("\u00030?6([^\u0003\u000F]+)", "<font color=\"purple\">$1</font>")
.replaceAll("\u00030?7([^\u0003\u000F]+)", "<font color=\"orange\">$1</font>")
.replaceAll("\u00030?8([^\u0003\u000F]+)", "<font color=\"yellow\">$1</font>")
.replaceAll("\u00030?9([^\u0003\u000F]+)", "<font color=\"chartreuse\">$1</font>")
.replaceAll("\u000300?([^\u0003\u000F]+)", "<font color=\"white\">$1</font>");
}

@Override
Expand Down

0 comments on commit 2d683cf

Please sign in to comment.