Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

titaniumdecoy

macrumors member
Original poster
Oct 13, 2005
86
0
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?
 

newb16

macrumors regular
Feb 27, 2008
100
0
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?

Using ansi sequences, like echo -e "\e[33myellow" ,
where \e is ESC (and clicolor is not required here ).
 

titaniumdecoy

macrumors member
Original poster
Oct 13, 2005
86
0
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?
 

Enuratique

macrumors 6502
Apr 28, 2008
276
0
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?

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.