View Full Version : Printing to the terminal in color
titaniumdecoy
Jul 3, 2008, 09:34 PM
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?
Cromulent
Jul 4, 2008, 03:25 AM
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?
Use the ncurses library.
newb16
Jul 4, 2008, 03:37 AM
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
Jul 7, 2008, 01:00 AM
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
Jul 7, 2008, 01:11 AM
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.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.