0

I copy pasted this code after my class and before my main() method:

public static final String TEXT_RESET = "\u001B[0m";
public static final String TEXT_BLACK = "\u001B[30m";
public static final String TEXT_RED = "\u001B[31m";
public static final String TEXT_GREEN = "\u001B[32m";
public static final String TEXT_YELLOW = "\u001B[33m";
public static final String TEXT_BLUE = "\u001B[34m";
public static final String TEXT_PURPLE = "\u001B[35m";
public static final String TEXT_CYAN = "\u001B[36m";
public static final String TEXT_WHITE = "\u001B[37m";

I typed it out as a command like this:

System.out.println(TEXT_BLUE + "text" + TEXT_RESET);

But the output in console was this:

[34mtext[0m

How can I fix this problem and display colour successfully in my console?

Hagelsnow
  • 45
  • 4
  • Does this answer your question? [How to print color in console using System.out.println?](https://stackoverflow.com/questions/5762491/how-to-print-color-in-console-using-system-out-println) It suggests that what you're doing might not work in Windows. – Henry Twist Nov 17 '21 at 07:48
  • 2
    I recommend you to never use ASCII escape code, if you are not able to determine terminal capabilities. It is just very bad programming practice. Use libraries (e.g. terminfo or ncurses see: https://stackoverflow.com/questions/439799/whats-a-good-java-curses-like-library-for-terminal-applications, or other pages on SO) – Giacomo Catenazzi Nov 17 '21 at 08:27
  • It depends on your console. – Ole V.V. Nov 17 '21 at 08:39

0 Answers0