0

I have built an application that prints a lot of results and i need to keep track of them and be able to read them in a easy way so i decided to use ANSI colors to print the output colored but this is the output i obtain:

[30m[37m[36m[35m[34m[*] Sending: 'UnknownTue Apr 09 17:17:36 GMT+02:00 2019' [*][0m[0m[0m[0m[0m

when i use this method in the print:

System.out.println(Colors.color("[*] Sending: \'"+message+"\' [*]","blue"));

and this is the Colors class i have defined:

public class Colors {
    private static final String reset = "\u001B[0m";
    private static final String black = "\u001B[30m";
    private static final String red = "\u001B[31m";
    private static final String green = "\u001B[32m";
    private static final String yellow = "\u001B[33m";
    private static final String blue = "\u001B[34m";
    private static final String purple = "\u001B[35m";
    private static final String cyan = "\u001B[36m";
    private static final String white = "\u001B[37m";

    public static String color(String toColor, String color){
        switch(color){
            case "red":
                toColor = red+toColor+reset;
            case "green":
                toColor = green+toColor+reset;
            case "yellow":
                toColor = yellow+toColor+reset;
            case "blue":
                toColor = blue+toColor+reset;
            case "purple":
                toColor = purple+toColor+reset;
            case "cyan":
                toColor = cyan+toColor+reset;
            case "white":
                toColor = white+toColor+reset;
            case "black":
                toColor = black+toColor+reset;
        }
        return toColor;
    }
}

This is what i pass to the function that prints:

String name = "Unknown"+ this.date;
connection.postMessage(this.sp.getString("Name", name));
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
DRE
  • 263
  • 8
  • 35

0 Answers0