Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java: colorful system.out messages on console

I would like my command line java program to output colored texts into the unix console. I am specifically using gnome-terminal on Ubuntu 10.4. I am able to get colors with something like echo "\033[01;32m"Hello on the terminal.

How can I trigger this with java code? Thanks

like image 789
artsince Avatar asked Nov 15 '10 08:11

artsince


People also ask

How do you add color to text in Java?

Syntax: System. out. println(ANSI_COLORNAME + "This text is colored" + ANSI_RESET);

What do the colors mean in Java?

The colors mean nothing, it's just your IDE highlighting different keywords to make your code easier to read.


1 Answers

If you don't care about terminal compatibility, just replace echo with System.out.println( above. For example,

System.out.println("\033[01;32mHello\n");
like image 127
Nicholas Riley Avatar answered Oct 08 '22 00:10

Nicholas Riley