PDA

View Full Version : colours



rxg00u
04-20-2002, 10:09 AM
hi every1
i wnated to know if it is possible to change text colour being outputed on a unix compiler (g++). I have searched the FAQ but it seems that most of the stuff on there was concerned with windows / dos programming.
thanks alot for ur time :D

Deckard
04-20-2002, 10:12 AM
Hello,

Are you interested in changing the color of the output of g++, or are you intending to have your programs display colored text?

rxg00u
04-20-2002, 10:28 AM
hi what i would like is for the output o have certain text to be in one colour and the next in the other for example


.......
cout<<"This is red text";
//code to change colour
cout<<this is blue text";

but i seem to be havin problems finding out if there are method avaible within the += livaries that is able to perform somthing like this.
thanks alot

Deckard
04-20-2002, 10:48 AM
What you need is ncurses. Check out the man pages for ncurses and curs_color. I think you will find them most useful.

rxg00u
04-20-2002, 12:10 PM
hey thanks for al ur help
is there anywhere that u know of where there are source examples for ncurses becausei cant really seem to understand it properly
thanks again

xlordt
04-20-2002, 05:19 PM
enjoy :: its not my own code but part of it is.. so again enjoy..



#include <ncurses.h>

void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string);

int main(int argc, char *argv[])
{

initscr();
if(has_colors() == FALSE)
{
endwin();
printf("You terminal does not support color\n");
exit(1);
}
start_color(); /* Start color */
init_pair(1, COLOR_BLUE, COLOR_YELLOW);

attron(COLOR_PAIR(1));
print_in_middle(stdscr, LINES / 2, 0, 0, "Viola !!! In color ...");
attroff(COLOR_PAIR(1));
sleep(10);
endwin();
}

void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string)
{

int length, x, y;
float temp;
if(win == NULL)
win = stdscr;
getyx(win, y, x);
if(startx != 0)
x = startx;
if(starty != 0)
y = starty;
if(width == 0)
width = 80; length = strlen(string);
temp = (width - length)/ 2;
x = startx + (int)temp;
mvwprintw(win, y, x, "%s", string);
refresh();
}