Change java console output color

I was wondering if I have the opportunity to set the color of the text that I will display on the console in Java. It doesn’t matter if it is system-specific, since the program will only work on my Windows 7 x64 laptop.

This question: Changing the color in the java eclipse console was asked a few weeks ago and had a good solution (by @VonC) for a similar problem, however, it addressed only the problem inside eclipse.

Is it possible to achieve the same effect if I execute my program from the command line? And if so, how?

+6
source share
3 answers
+10
source

Another library you are interested in is Jansi: http://jansi.fusesource.org/

Jansi interprets ANSI code and formats them for console output. It works for both unix and windows.

Update 11/2014: you can also see the github page

+7
source

this is yours .... read on http://jansi.fusesource.org/

public static final String ANSI_RESET = "\u001B[0m"; public static final String ANSI_BLACK = "\u001B[30m"; public static final String ANSI_RED = "\u001B[31m"; public static final String ANSI_GREEN = "\u001B[32m"; public static final String ANSI_YELLOW = "\u001B[33m"; public static final String ANSI_BLUE = "\u001B[34m"; public static final String ANSI_PURPLE = "\u001B[35m"; public static final String ANSI_CYAN = "\u001B[36m"; public static final String ANSI_WHITE = "\u001B[37m"; 
+5
source

Source: https://habr.com/ru/post/887528/


All Articles