Added colors
This commit is contained in:
@@ -15,7 +15,7 @@ public class Client {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
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);
|
Scanner scanner = new Scanner(System.in);
|
||||||
while(true) {
|
while(true) {
|
||||||
String message = scanner.nextLine();
|
String message = scanner.nextLine();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.net.InetSocketAddress;
|
|||||||
import network.PacketHandler;
|
import network.PacketHandler;
|
||||||
import network.SocketReader;
|
import network.SocketReader;
|
||||||
import network.SocketWriter;
|
import network.SocketWriter;
|
||||||
|
import network.protocol.ANSIColor;
|
||||||
import network.protocol.Packet;
|
import network.protocol.Packet;
|
||||||
import network.protocol.PacketVisitor;
|
import network.protocol.PacketVisitor;
|
||||||
import network.protocol.packets.ChatMessagePacket;
|
import network.protocol.packets.ChatMessagePacket;
|
||||||
@@ -53,7 +54,7 @@ public class ClientConnexion implements PacketVisitor, PacketHandler{
|
|||||||
sb.append(" ");
|
sb.append(" ");
|
||||||
sb.append(packet.getChatter());
|
sb.append(packet.getChatter());
|
||||||
sb.append(" : ");
|
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);
|
System.out.println(sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
ChatApp/src/network/protocol/ANSIColor.java
Normal file
16
ChatApp/src/network/protocol/ANSIColor.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user