colorz

This is a discussion on colorz within the Linux Programming forums, part of the Platform Specific Boards category; ok im tring to make this pring out in the color that i have in the code.. but it semez ...

  1. #1
    Unregistered
    Guest

    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

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    8
    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.

  3. #3
    Unregistered
    Guest
    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;
    
     }

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    8
    You should be using printw(), because it outputs to the standard screen. wprinft() is for wide-character printing.

  5. #5
    Unregistered
    Guest
    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

  6. #6
    Registered User
    Join Date
    Aug 2002
    Posts
    8
    /* 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;

    }

  7. #7
    Unregistered
    Guest
    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

  8. #8
    Registered User alex's Avatar
    Join Date
    Sep 2001
    Posts
    132
    Hi!

    Maybe the TERM-variable contains the wrong identification string? (type "echo $TERM")

    "xterm" and "linux" support color;
    "vt100" and "vt102" do not.

    alex

  9. #9
    Unregistered
    Guest
    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

  10. #10
    Registered User alex's Avatar
    Join Date
    Sep 2001
    Posts
    132
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. colorz
    By xlordt in forum Linux Programming
    Replies: 1
    Last Post: 02-19-2002, 01:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21