PDA

View Full Version : sending color characters to the terminal




mward333
Sep 17, 2007, 08:33 AM
I'm writing a C++ program that runs in the terminal. It would be absolutely wonderful to send some of the characters to the terminal in color instead of the usual black.

Of course C++ does not have built-in color support...

Instead, what I am hoping to do, for instance, is send an ASCII or Unicode sequence to the terminal as the program runs, saying (for instance), ok now we want the current text to be red, ok now we want the current text to be blue, etc., etc.

There must be an ASCII or Unicode sequence that tells the terminal to switch colors as the program executes. Can somebody point me to a useful example about this?



lazydog
Sep 17, 2007, 09:15 AM
Hi

I think you need to use is ansi escape codes. Try wiipedia (http://en.wikipedia.org/wiki/ANSI_escape_code)!

b e n

mward333
Sep 17, 2007, 09:23 AM
Hi

I think you need to use is ansi escape codes. Try wiipedia (http://en.wikipedia.org/wiki/ANSI_escape_code)!

b e n

b e n, thank you, that looks like it might do that trick. Let me try to write a few lines of code to test this.

Thank you so much for your advice.

lazydog
Sep 17, 2007, 09:48 AM
No problem…*but will your 8 core Mac and 3 30" displays be able to handle the stress of displaying ascii in colour :)

b e n

mward333
Sep 17, 2007, 09:50 AM
No problem…*but will your 8 core Mac and 3 30" displays be able to handle the stress of displaying ascii in colour :)

b e n

b e n...... Your advice did the trick. I just got it working perfectly. Thank you. By the way, I really appreciate your help.

ha ha.... can my Mac Pro handle it? That was funny! :)

Thanks again.

mward333
Sep 17, 2007, 11:20 AM
OK, so now I have colors working great using the escape sequences, as "b e n" suggested.

Is there a way to use more than 8 text colors? (Sure, I know switching from C++ to Java is an obvious tip, but I need to stick with C++.)

Any thoughts?