Added colors

This commit is contained in:
Clément
2025-02-28 14:58:42 +01:00
parent ac631cbe0f
commit f0a9617649
3 changed files with 19 additions and 2 deletions

View File

@@ -15,7 +15,7 @@ public class Client {
public static void main(String[] args) {
try {
Client client = new Client(new InetSocketAddress("localhost", 6665));
Client client = new Client(new InetSocketAddress("192.168.199.131", 6665));
Scanner scanner = new Scanner(System.in);
while(true) {
String message = scanner.nextLine();

View File

@@ -7,6 +7,7 @@ import java.net.InetSocketAddress;
import network.PacketHandler;
import network.SocketReader;
import network.SocketWriter;
import network.protocol.ANSIColor;
import network.protocol.Packet;
import network.protocol.PacketVisitor;
import network.protocol.packets.ChatMessagePacket;
@@ -53,7 +54,7 @@ public class ClientConnexion implements PacketVisitor, PacketHandler{
sb.append(" ");
sb.append(packet.getChatter());
sb.append(" : ");
sb.append(packet.getContent());
sb.append(ANSIColor.formatString(packet.getContent() + "&n")); // make the color back to normal at the end of every message
System.out.println(sb);
}

View File

@@ -0,0 +1,16 @@
package network.protocol;
public class ANSIColor {
public static final String RESET = "\u001B[0m";
public static final String BLACK = "\u001B[30m";
public static final String RED = "\u001B[31m";
public static final String GREEN = "\u001B[32m";
public static final String BLUE = "\u001B[34m";
public static String formatString(String message){
return message.replace("&r", RED)
.replace("&g", GREEN)
.replace("&b", BLUE)
.replace("&n", RESET);
}
}