diff --git a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java index a2babf8..1c3988a 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java @@ -153,6 +153,15 @@ public class ClientLauncherTUI { .completer(new StringsCompleter("localhost")) .build(); + view.setLineReader(loginReader); + try { + return doLoginInner(controller, loginReader, ipReader); + } finally { + view.setLineReader(gameReader); + } + } + + private boolean doLoginInner(ClientController controller, LineReader loginReader, LineReader ipReader) { String username, networkStr, ip; int nPlayers; @@ -166,7 +175,7 @@ public class ClientLauncherTUI { System.exit(0); return false; } catch (NumberFormatException e) { - System.out.println("Invalid number of players."); + loginReader.printAbove("\033[31mInvalid number of players.\033[0m"); return false; } @@ -180,16 +189,14 @@ public class ClientLauncherTUI { try { myIP = InterfaceResolver.resolveLocalInterface(ip); } catch (Exception e) { - System.out.println("Cannot resolve local interface: " + e.getMessage()); + loginReader.printAbove("\033[31mCannot resolve local interface: " + e.getMessage() + "\033[0m"); return false; } System.setProperty("java.rmi.server.hostname", myIP); client = new RMIClient(controller, ip, NetworkConfig.RMI_PORT, myIP); ErrorType err = client.connect(username, nPlayers); if (err != null) { - terminal.writer().print("\033[H\033[2J"); - terminal.writer().flush(); - System.out.println("Errore: " + err); + loginReader.printAbove("\033[31mErrore: " + err + "\033[0m"); return false; } System.out.println("Connected via RMI, waiting for other players..."); @@ -199,16 +206,14 @@ public class ClientLauncherTUI { client = new TCPClient(controller, ip, NetworkConfig.TCP_PORT, NetworkConfig.HEARTBEAT_PORT); ErrorType err = client.connect(username, nPlayers); if (err != null) { - terminal.writer().print("\033[H\033[2J"); - terminal.writer().flush(); - System.out.println("Errore: " + err); + loginReader.printAbove("\033[31mErrore: " + err + "\033[0m"); return false; } System.out.println("Connected via TCP, waiting for other players..."); controller.setClient(client); } else { - System.out.println("Unknown network type '" + networkStr + "'. Use rmi or tcp."); + loginReader.printAbove("\033[31mUnknown network type '" + networkStr + "'. Use rmi or tcp.\033[0m"); return false; } return true; @@ -232,7 +237,6 @@ public class ClientLauncherTUI { node("totem"), node("skip"), node("clear"), - node("help"), node("details", node("buildings"), node("events"), node("characters")), node("rematch"), node("quit") @@ -269,7 +273,6 @@ public class ClientLauncherTUI { } case "skip" -> controller.skipTurn(); case "clear" -> handleRender(); - case "help" -> gameReader.printAbove("Commands: slot, draw, totem, skip, clear, help, details, rematch, quit"); case "details" -> { if (parts.length > 1 && parts[1].equalsIgnoreCase("buildings")) gameReader.printAbove(BUILDING_DETAILS); diff --git a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java index 1e1c94d..6f8a182 100644 --- a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java @@ -90,18 +90,20 @@ public class TUI implements IView { GameStages stage = model.currentState.getGameStage(); if (stage == GameStages.TOTEM_CHOICE) { display(buildTotemsContent()); - printLine("Type: totem "); + printLine("\033[2mCommands: totem \033[0m"); } else if (stage == GameStages.ENDED) { display(buildStandingContent()); printLine("Type 'rematch' to play again or 'quit' to exit"); } else { display(buildBoardContent()); + printLine("\033[2mCommands: slot | draw upper|lower tribe|building | totem | skip | clear | details buildings|events|characters | rematch | quit\033[0m"); } } /** Renders the board + menu (top) and all players' hands in a grid (bottom). */ public void renderBoard() { display(buildBoardContent()); + printLine("Commands: slot | draw upper|lower tribe|building | totem | skip | clear | details buildings|events|characters | rematch | quit"); } /** @@ -124,7 +126,8 @@ public class TUI implements IView { text += "\nPress any key to continue"; } } - printLine(text); + render(); + printLine("\033[31m" + text + "\033[0m"); } // ── Content builders (return strings, do not print) ───────────────────────