Skip to content

Commit 4ea7f02

Browse files
Full ANSI support in GUI + improve message cache
1 parent 75921e5 commit 4ea7f02

File tree

14 files changed

+353
-165
lines changed

14 files changed

+353
-165
lines changed

gradle/libs.versions.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ via-bedrock = "0.0.5-SNAPSHOT"
1313
flatlaf = "3.3"
1414
flatlaf-inter-version = "4.0"
1515
flatlaf-jetbrains-mono-version = "2.304"
16+
kyori = "4.15.0"
1617

1718
[plugins]
1819
blossom = "net.kyori.blossom:2.1.0"
@@ -60,8 +61,9 @@ via-aprilfools = { module = "net.raphimc:ViaAprilFools", version.ref = "via-apri
6061
via-loader = { module = "net.raphimc:ViaLoader", version.ref = "via-loader" }
6162
via-bedrock = { module = "net.raphimc:ViaBedrock", version.ref = "via-bedrock" }
6263
snakeyaml = "org.yaml:snakeyaml:2.2"
63-
kyori-plain = "net.kyori:adventure-text-serializer-plain:4.15.0"
64-
kyori-gson = "net.kyori:adventure-text-serializer-gson:4.15.0"
64+
kyori-plain = { module = "net.kyori:adventure-text-serializer-plain", version.ref = "kyori"}
65+
kyori-gson = { module = "net.kyori:adventure-text-serializer-gson", version.ref = "kyori" }
66+
kyori-ansi = { module = "net.kyori:adventure-text-serializer-ansi", version.ref = "kyori" }
6567
commons-validator = "commons-validator:commons-validator:1.8.0"
6668
commons-io = "commons-io:commons-io:2.15.1"
6769
httpclient = "org.apache.httpcomponents:httpclient:4.5.14"
@@ -91,5 +93,5 @@ log4j = ["log4j-api", "log4j-core", "log4j-slf4j2-impl", "log4j-iostreams", "log
9193
grpc = ["grpc-proto", "grpc-services", "grpc-stub", "grpc-netty"]
9294
mixins = ["classtransform-mixinstranslator", "classtransform-mixinsdummy", "classtransform-additionalclassprovider"]
9395
flatlaf = ["flatlaf", "flatlaf-extras", "flatlaf-intellij-themes", "flatlaf-fonts-inter", "flatlaf-fonts-jetbrains-mono"]
94-
kyori = ["kyori-plain", "kyori-gson"]
96+
kyori = ["kyori-plain", "kyori-gson", "kyori-ansi"]
9597
ansi4j = ["ansi4j-core-api", "ansi4j-core-impl"]

src/main/java/net/pistonmaster/soulfire/SoulFireBootstrap.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private SoulFireBootstrap() {}
7272

7373
@SuppressWarnings("unused")
7474
public static void bootstrap(String[] args, List<ClassLoader> classLoaders) {
75-
injectAnsi();
75+
AnsiConsole.systemInstall();
7676
setupLogging(SettingsHolder.EMPTY);
7777

7878
injectExceptionHandler();
@@ -165,15 +165,6 @@ private static void initPlugins(List<ClassLoader> classLoaders) {
165165
}
166166
}
167167

168-
/** RGB support for terminals. */
169-
private static void injectAnsi() {
170-
if (System.console() == null) {
171-
return;
172-
}
173-
174-
AnsiConsole.systemInstall();
175-
}
176-
177168
public static void setupLogging(SettingsHolder settingsHolder) {
178169
var level = settingsHolder.get(DevSettings.CORE_DEBUG) ? Level.DEBUG : Level.INFO;
179170
var nettyLevel = settingsHolder.get(DevSettings.NETTY_DEBUG) ? Level.DEBUG : Level.INFO;

src/main/java/net/pistonmaster/soulfire/client/gui/libs/MessageLogPanel.java

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import javax.swing.text.StyledDocument;
4848
import lombok.Setter;
4949
import lombok.extern.slf4j.Slf4j;
50+
import net.pistonmaster.soulfire.server.util.XtermPalette256;
5051
import pk.ansi4j.core.DefaultFunctionFinder;
5152
import pk.ansi4j.core.DefaultParserFactory;
5253
import pk.ansi4j.core.DefaultTextHandler;
@@ -157,17 +158,82 @@ private void updateTextComponent() {
157158
var functionFragment = (FunctionFragment) fragment;
158159
if (functionFragment.getFunction()
159160
== ControlSequenceFunction.SGR_SELECT_GRAPHIC_RENDITION) {
160-
StyleConstants.setForeground(defaultAttributes, switch ((int) functionFragment.getArguments().getFirst().getValue()) {
161-
case 30 -> Color.decode("#090300");
162-
case 31 -> Color.decode("#FF0000");
163-
case 32 -> Color.decode("#00FF00");
164-
case 33 -> Color.decode("#FFFF00");
165-
case 34 -> Color.decode("#0000FF");
166-
case 35 -> Color.decode("#FF00FF");
167-
case 36 -> Color.decode("#00FFFF");
168-
case 37 -> Color.decode("#FFFFFF");
169-
default -> Color.decode("#FFFFFF");
170-
});
161+
var sgr = (int) functionFragment.getArguments().getFirst().getValue();
162+
163+
switch (sgr) {
164+
case 0 -> {
165+
for (var attributes = defaultAttributes.getAttributeNames();
166+
attributes.hasMoreElements(); ) {
167+
var name = attributes.nextElement();
168+
defaultAttributes.removeAttribute(name);
169+
}
170+
}
171+
case 1 -> StyleConstants.setBold(defaultAttributes, true);
172+
case 3 -> StyleConstants.setItalic(defaultAttributes, true);
173+
case 4 -> StyleConstants.setUnderline(defaultAttributes, true);
174+
case 9 -> StyleConstants.setStrikeThrough(defaultAttributes, true);
175+
case 22 -> StyleConstants.setBold(defaultAttributes, false);
176+
case 23 -> StyleConstants.setItalic(defaultAttributes, false);
177+
case 24 -> StyleConstants.setUnderline(defaultAttributes, false);
178+
case 29 -> StyleConstants.setStrikeThrough(defaultAttributes, false);
179+
case 30 ->
180+
StyleConstants.setForeground(defaultAttributes, new Color(1, 1, 1));
181+
case 31 ->
182+
StyleConstants.setForeground(defaultAttributes, new Color(222, 56, 43));
183+
case 32 ->
184+
StyleConstants.setForeground(defaultAttributes, new Color(57, 181, 74));
185+
case 33 ->
186+
StyleConstants.setForeground(defaultAttributes, new Color(255, 199, 6));
187+
case 34 ->
188+
StyleConstants.setForeground(defaultAttributes, new Color(0, 111, 184));
189+
case 35 ->
190+
StyleConstants.setForeground(
191+
defaultAttributes, new Color(118, 38, 113));
192+
case 36 ->
193+
StyleConstants.setForeground(
194+
defaultAttributes, new Color(44, 181, 233));
195+
case 37, 39 ->
196+
StyleConstants.setForeground(
197+
defaultAttributes, new Color(204, 204, 204));
198+
case 38 -> {
199+
var secondArgument =
200+
(int) functionFragment.getArguments().get(1).getValue();
201+
StyleConstants.setForeground(
202+
defaultAttributes,
203+
switch (secondArgument) {
204+
case 2 -> {
205+
var r = (int) functionFragment.getArguments().get(2).getValue();
206+
var g = (int) functionFragment.getArguments().get(3).getValue();
207+
var b =
208+
(int) functionFragment.getArguments().getLast().getValue();
209+
yield new Color(r, g, b);
210+
}
211+
case 5 -> {
212+
var id = (int) functionFragment.getArguments().get(2).getValue();
213+
yield XtermPalette256.getColor(id);
214+
}
215+
default -> Color.decode("#FFFFFF");
216+
});
217+
}
218+
case 90 ->
219+
StyleConstants.setForeground(
220+
defaultAttributes, new Color(128, 128, 128));
221+
case 91 ->
222+
StyleConstants.setForeground(defaultAttributes, new Color(255, 0, 0));
223+
case 92 ->
224+
StyleConstants.setForeground(defaultAttributes, new Color(0, 255, 0));
225+
case 93 ->
226+
StyleConstants.setForeground(defaultAttributes, new Color(255, 255, 0));
227+
case 94 ->
228+
StyleConstants.setForeground(defaultAttributes, new Color(0, 0, 255));
229+
case 95 ->
230+
StyleConstants.setForeground(defaultAttributes, new Color(255, 0, 255));
231+
case 96 ->
232+
StyleConstants.setForeground(defaultAttributes, new Color(0, 255, 255));
233+
case 97 ->
234+
StyleConstants.setForeground(
235+
defaultAttributes, new Color(255, 255, 255));
236+
}
171237
} else if (functionFragment.getFunction() == C0ControlFunction.LF_LINE_FEED) {
172238
document.insertString(document.getLength(), "\n", defaultAttributes);
173239
}

src/main/java/net/pistonmaster/soulfire/client/gui/navigation/AccountPanel.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,18 @@ public AccountPanel(GUIManager guiManager, GUIFrame parent, CardsContainer cards
6262
toolBar.setFloatable(false);
6363
var addButton = new JButton("+");
6464
addButton.setToolTipText("Add accounts");
65-
addButton.addMouseListener(new MouseAdapter() {
66-
public void mousePressed(MouseEvent e) {
67-
var menu = new JPopupMenu();
68-
menu.add(createAccountLoadButton(guiManager, parent, AuthType.OFFLINE));
69-
menu.add(createAccountLoadButton(guiManager, parent, AuthType.MICROSOFT_JAVA));
70-
menu.add(createAccountLoadButton(guiManager, parent, AuthType.MICROSOFT_BEDROCK));
71-
menu.add(createAccountLoadButton(guiManager, parent, AuthType.THE_ALTENING));
72-
menu.add(createAccountLoadButton(guiManager, parent, AuthType.EASYMC));
73-
menu.show(e.getComponent(), e.getX(), e.getY());
74-
}
75-
});
65+
addButton.addMouseListener(
66+
new MouseAdapter() {
67+
public void mousePressed(MouseEvent e) {
68+
var menu = new JPopupMenu();
69+
menu.add(createAccountLoadButton(guiManager, parent, AuthType.OFFLINE));
70+
menu.add(createAccountLoadButton(guiManager, parent, AuthType.MICROSOFT_JAVA));
71+
menu.add(createAccountLoadButton(guiManager, parent, AuthType.MICROSOFT_BEDROCK));
72+
menu.add(createAccountLoadButton(guiManager, parent, AuthType.THE_ALTENING));
73+
menu.add(createAccountLoadButton(guiManager, parent, AuthType.EASYMC));
74+
menu.show(e.getComponent(), e.getX(), e.getY());
75+
}
76+
});
7677

7778
toolBar.add(addButton);
7879
toolBar.setBorder(BorderFactory.createLineBorder(UIManager.getColor("Component.borderColor")));

src/main/java/net/pistonmaster/soulfire/client/gui/navigation/ProxyPanel.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,16 @@ public ProxyPanel(GUIManager guiManager, GUIFrame parent, CardsContainer cardsCo
6262
toolBar.setFloatable(false);
6363
var addButton = new JButton("+");
6464
addButton.setToolTipText("Add proxies");
65-
addButton.addMouseListener(new MouseAdapter() {
66-
public void mousePressed(MouseEvent e) {
67-
var menu = new JPopupMenu();
68-
menu.add(createProxyLoadButton(guiManager, parent, ProxyType.HTTP));
69-
menu.add(createProxyLoadButton(guiManager, parent, ProxyType.SOCKS4));
70-
menu.add(createProxyLoadButton(guiManager, parent, ProxyType.SOCKS5));
71-
menu.show(e.getComponent(), e.getX(), e.getY());
72-
}
73-
});
65+
addButton.addMouseListener(
66+
new MouseAdapter() {
67+
public void mousePressed(MouseEvent e) {
68+
var menu = new JPopupMenu();
69+
menu.add(createProxyLoadButton(guiManager, parent, ProxyType.HTTP));
70+
menu.add(createProxyLoadButton(guiManager, parent, ProxyType.SOCKS4));
71+
menu.add(createProxyLoadButton(guiManager, parent, ProxyType.SOCKS5));
72+
menu.show(e.getComponent(), e.getX(), e.getY());
73+
}
74+
});
7475

7576
toolBar.add(addButton);
7677
toolBar.setBorder(BorderFactory.createLineBorder(UIManager.getColor("Component.borderColor")));

src/main/java/net/pistonmaster/soulfire/server/SoulFireServer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@
9696
@Getter
9797
public class SoulFireServer {
9898
public static final Gson GENERAL_GSON = new Gson();
99+
public static final ComponentFlattener FLATTENER =
100+
ComponentFlattener.basic().toBuilder()
101+
.mapper(TranslatableComponent.class, TranslationMapper.INSTANCE)
102+
.build();
99103
public static final PlainTextComponentSerializer PLAIN_MESSAGE_SERIALIZER =
100104
PlainTextComponentSerializer.builder()
101-
.flattener(
102-
ComponentFlattener.basic().toBuilder()
103-
.mapper(TranslatableComponent.class, TranslationMapper.INSTANCE)
104-
.build())
105+
.flattener(FLATTENER)
105106
.build();
106107

107108
private final Injector injector =

src/main/java/net/pistonmaster/soulfire/server/api/event/bot/ChatMessageReceiveEvent.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ public String parseToText() {
4040
return SoulFireServer.PLAIN_MESSAGE_SERIALIZER.serialize(message);
4141
}
4242

43-
public boolean isFromPlayer() {
44-
return sender != null;
45-
}
46-
4743
public record ChatMessageSender(UUID senderUUID, String senderName) {
4844
public static ChatMessageSender fromClientboundPlayerChatPacket(
4945
ClientboundPlayerChatPacket packet) {

0 commit comments

Comments
 (0)