vrbadev
vrbadev

Reputation: 506

Colors from console saved in text file as eg. [33;1m

I have serious problem. I have one program which works with Command prompt, and the program can write color messages into it. And it also saves the messages to text .log file. But when I read the log with my java program, it writes instand of yellow text this: [33;1m before text which should be yellow. I noticed that [37;22m is for dark green, [37;1m is for white etc. (Before this code is a small arrow, but I can't paste it anywhere.)

Does anyone know what this codes suppose to be and how to rewrite it to java.awt.Color.Color which I am able to use? Thanks.

Upvotes: 0

Views: 1440

Answers (3)

Freedom_Ben
Freedom_Ben

Reputation: 11953

Yes these are escape sequences used to signal to a terminal that you want to change the current color (this style is also used for telling the terminal to move the cursor as well.). What type of terminal is this for? AFAIK Yellow should be \033[1;33m, dark green should be \033[0;32m, and White should be \033[1;37m. To switch back to the previous color would be \033[0m.

As for converting them to Java Color, I don't believe there is a built in API call for that, however it should be pretty easy to write one yourself.

If you are writing for Linux/Bash here is a handy guide:

Upvotes: 1

NPE
NPE

Reputation: 500673

These are ANSI terminal codes. I am afraid I can't help with the second part of your question.

Upvotes: 2

Jesper
Jesper

Reputation: 206896

These are probably ANSI escape codes.

Upvotes: 2

Related Questions