-
colorz
ok im tring to make this pring out in the color that i have in the code.. but it semez not to work.. i remember i did it last time but .. i cant remember now.. can anyone please help me figure this one out ? thanx..
Code:
#include <ncurses.h>
int main()
{
initscr();
noecho();
cbreak();
start_color();
refresh();
init_pair(2, COLOR_BLUE, COLOR_RED);
attron(COLOR_PAIR(2));
printf("hello colorz");
attroff(COLOR_PAIR(2));
sleep(3);
endwin();
return 0;
}
so please if anyone can help me fix this.. i would be really apresiated.... thanx again
-
The call you made to printf() prints output to the stdout. When you use ncurses, you need to print to the standard screen. Also you didn't call refresh(), so there would be now way to see the output. So basically, all you need to do is....
Change printf() to printw() and add refresh(); after the printw() call.
-
ok im still getting an error here... please take a look....
Code:
#include <ncurses.h>
int main()
{
initscr();
noecho();
cbreak();
start_color();
init_pair(2, COLOR_RED, COLOR_RED);
attron(COLOR_PAIR(2));
wprintf("hello colorz");
refresh();
attroff(COLOR_PAIR(2));
sleep(3);
endwin();
return 0;
}
-
You should be using printw(), because it outputs to the standard screen. wprinft() is for wide-character printing.
-
i did that to and it still didnt print out anything.... can you post the code in your format so i can see what i am doing wrong
-
/* Maybe your terminal doesn't support colors. This seems to work on my system. */
#include <ncurses.h>
int main()
{
initscr();
noecho();
cbreak();
start_color();
refresh();
init_pair(2, COLOR_BLUE, COLOR_RED);
attron(COLOR_PAIR(2));
printw("hello colorz");
refresh();
attroff(COLOR_PAIR(2));
sleep(3);
endwin();
return 0;
}
-
that is the thing my term do support colorz.. im running RH7.3 and i have had run a simple program that was created by someone else.. and this one is by me but itz not working.. ggrrrr
-
Hi!
Maybe the TERM-variable contains the wrong identification string? (type "echo $TERM")
"xterm" and "linux" support color;
"vt100" and "vt102" do not.
alex
-
heh?
sorry alex.. i dont get what you are saying.. but im tring to code this in ncurses... i remember i did it last time bit now itz not working... thanx for your replay though
-
Hi,
The program works perfectly here: displaying colored text in the upper-left corner of the screen.
Could you type "echo $TERM" in your terminal, where you are trying to run the program? TERM is an environment variable, describing your terminal capabilities. ncurses uses this variable to determine what escape sequences are supported by the terminal.
The escape sequence for the linux console are described in the man-page console_codes. For example:
Code:
printf("\033[34;41mThis is blue text on a red background.\033[0m\n");
will print colored text on terminals supporting the escape sequence, but it may print garbage on terminals that do not support it. ncurses provides a single interface to almost all terminal types, but still has to know which terminal type it has to send its output to.
greetinx,
alex