From 5e2797946a3d63de9142d79b241788e2284f8eab Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 26 Mar 2016 13:45:30 +0100 Subject: Implement simulation terminal output coloring --- .../epfl/xblast/server/debug/GameStatePrinter.java | 31 +++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/ch/epfl') diff --git a/src/ch/epfl/xblast/server/debug/GameStatePrinter.java b/src/ch/epfl/xblast/server/debug/GameStatePrinter.java index d4d91e5..a846421 100644 --- a/src/ch/epfl/xblast/server/debug/GameStatePrinter.java +++ b/src/ch/epfl/xblast/server/debug/GameStatePrinter.java @@ -16,6 +16,25 @@ import java.util.List; */ public final class GameStatePrinter { + private enum ANSIColor { + + BLACK(0), RED(1), GREEN(2), YELLOW(3), BLUE(4), MAGENTA(5), CYAN(6), WHITE(7); + + private static final String CSI = "\u001b["; + private static final String END = "m"; + private static final int SET_COMMAND = 4; + + private final int code; + + ANSIColor(int code) { + this.code = code; + } + + public String coloredText(String t) { + return String.format("%s%d%d%s%s%s%s", CSI, SET_COMMAND, this.code, END, t, CSI, END); + } + } + private GameStatePrinter() { } @@ -63,7 +82,7 @@ public final class GameStatePrinter { b.append('<'); break; } - return b.toString(); + return ANSIColor.CYAN.coloredText(b.toString()); } private static String stringForBlock(Block b) { @@ -71,15 +90,15 @@ public final class GameStatePrinter { case FREE: return " "; case INDESTRUCTIBLE_WALL: - return "##"; + return ANSIColor.BLACK.coloredText("##"); case DESTRUCTIBLE_WALL: - return "??"; + return ANSIColor.BLACK.coloredText("??"); case CRUMBLING_WALL: - return "¿¿"; + return ANSIColor.BLACK.coloredText("¿¿"); case BONUS_BOMB: - return "+b"; + return ANSIColor.GREEN.coloredText("+b"); case BONUS_RANGE: - return "+r"; + return ANSIColor.GREEN.coloredText("+r"); default: throw new Error(); } -- cgit v1.2.3