I was searching about changing output color for console in NetBeans and found this post. I tried the first answer and worked perfectly for changing colors. I tried the fifth answer and... worked too.
My question is: why the strings designated for every color are different in first and fifth?
First answer's example:
public static final String ANSI_BLUE = "\u001B[34m";
Fifth answer's example:
public static final String BLUE = "\033[0;34m"; // BLUE
I made a little research but I really couldn't figure why.
I appreciate an answer or help in pointing me to understand it.
The backslash notation denotes one byte local representation octal numbers. The \u
notation denotes 16 bit hexadecimal Unicode representation. Both \u001b
and \033
denote an ESC, so they are the same in that regard.
With that said, the two sequences are not the same. The first sequence gives one command, 34
, which means "foreground color blue". The second sequence gives two commands, separated by a semicolon. The second one is 34
, but the first one is 0
, which means "Reset".
So the first sequence changes color to blue, while the second one resets the settings and then sets the color to blue.