Printing to the terminal in color

Discussion in 'Mac Programming' started by titaniumdecoy, Jul 3, 2008.

  1. titaniumdecoy macrumors member

    Joined:
    Oct 13, 2005
    #1
    How can I print to the terminal in color? I have set CLICOLOR=1 so commands like ls display their output in color. How can I do this in my own command-line program?
     
  2. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #2
    Use the ncurses library.
     
  3. newb16 macrumors regular

    Joined:
    Feb 27, 2008
    #3
    Using ansi sequences, like echo -e "\e[33myellow" ,
    where \e is ESC (and clicolor is not required here ).
     
  4. titaniumdecoy thread starter macrumors member

    Joined:
    Oct 13, 2005
    #4
    Thanks. I am wondering, however, what built-in programs such as ls -G, vi, etc. use? Do these programs use either of the approaches mentioned?
     
  5. Enuratique macrumors 6502

    Joined:
    Apr 28, 2008
    #5
    I'm almost certain vi uses the ncurses library. As far as ls -G is concerned I don't know, it may be a bash/shell environment thing. ncurses isn't that hard to pick up - I had to use it for a lab assignment back in college for a Game of Life simulator. ncurses also has the ability to give menus and what not (think pine, putty, vi, etc) so it's not just line output, it's really a basic "windowing" system for the terminal.
     

Share This Page