sending color characters to the terminal

Discussion in 'Mac Programming' started by mward333, Sep 17, 2007.

  1. mward333 macrumors 6502a

    mward333

    Joined:
    Jan 24, 2004
    #1
    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?
     
  2. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #2
    Hi

    I think you need to use is ansi escape codes. Try wiipedia!

    b e n
     
  3. mward333 thread starter macrumors 6502a

    mward333

    Joined:
    Jan 24, 2004
    #3
    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.
     
  4. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #4
    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
     
  5. mward333 thread starter macrumors 6502a

    mward333

    Joined:
    Jan 24, 2004
    #5
    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.
     
  6. mward333 thread starter macrumors 6502a

    mward333

    Joined:
    Jan 24, 2004
    #6
    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?
     

Share This Page