escape strings for real tui

This commit is contained in:
Clément
2025-03-01 19:50:19 +01:00
parent f8f740f799
commit 10f6b059b1
4 changed files with 15 additions and 22 deletions

View File

@@ -23,6 +23,17 @@ public class Client {
login(pseudo); login(pseudo);
} }
public static void main(String[] args) {
ClientConsole console = new ClientConsole(new InetSocketAddress("localhost", 6665));
try {
console.joinThread();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("End !");
}
public void close() { public void close() {
this.connexion.sendPacket(new DisconnectPacket("Leaving")); this.connexion.sendPacket(new DisconnectPacket("Leaving"));
this.connexion.close(); this.connexion.close();

View File

@@ -41,7 +41,7 @@ public class ClientConnexion implements PacketVisitor, PacketHandler {
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
sendPacket(new HandshakePacket()); sendPacket(new HandshakePacket());
} }
new Thread(() -> waitForHandshake()).start(); new Thread(this::waitForHandshake).start();
} }
private void waitForHandshake() { private void waitForHandshake() {

View File

@@ -17,16 +17,6 @@ public class ClientConsole implements ClientListener {
private final Scanner scanner; private final Scanner scanner;
private volatile boolean connected = false; private volatile boolean connected = false;
public static void main(String[] args) {
ClientConsole console = new ClientConsole(new InetSocketAddress("localhost", 6665));
try {
console.joinThread();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("End !");
}
public ClientConsole(InetSocketAddress address) { public ClientConsole(InetSocketAddress address) {
this.inputThread = new Thread(this::inputLoop); this.inputThread = new Thread(this::inputLoop);
this.scanner = new Scanner(System.in); this.scanner = new Scanner(System.in);
@@ -109,6 +99,8 @@ public class ClientConsole implements ClientListener {
} else { } else {
this.client.SendChatMessage(message); this.client.SendChatMessage(message);
} }
System.out.print("\033[1A\r\033[2K"); // weird sequence to clear the line (but it works !)
System.out.flush();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@@ -8,17 +8,7 @@ import java.time.Instant;
import network.SocketWriter; import network.SocketWriter;
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.*;
import network.protocol.packets.CreateRoomPacket;
import network.protocol.packets.DisconnectPacket;
import network.protocol.packets.HandshakePacket;
import network.protocol.packets.JoinRoomPacket;
import network.protocol.packets.LeaveRoomPacket;
import network.protocol.packets.LoginPacket;
import network.protocol.packets.RequestRoomListPacket;
import network.protocol.packets.RoomListPacket;
import network.protocol.packets.SendChatMessagePacket;
import network.protocol.packets.ServerResponsePacket;
import network.protocol.packets.ServerResponsePacket.Response; import network.protocol.packets.ServerResponsePacket.Response;
public class ServerConnexion implements PacketVisitor { public class ServerConnexion implements PacketVisitor {