Thread: colours

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    22

    colours

    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

  2. #2
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    Hello,

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

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    22

    text colours

    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

  4. #4
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    What you need is ncurses. Check out the man pages for ncurses and curs_color. I think you will find them most useful.
    Jason Deckard

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    22
    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

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    enjoy :: its not my own code but part of it is.. so again enjoy..

    Code:
    #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();
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RGB Colours
    By rogster001 in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 04-22-2008, 12:56 PM
  2. Colours in DOS box
    By denizengt in forum Tech Board
    Replies: 1
    Last Post: 09-10-2003, 06:53 AM
  3. it's not colours
    By Skarr in forum Game Programming
    Replies: 0
    Last Post: 05-13-2003, 12:21 PM
  4. Changing Text/Background colours for window controls ...
    By Shag in forum Windows Programming
    Replies: 1
    Last Post: 11-16-2002, 11:57 AM
  5. Colours?
    By Fountain in forum C++ Programming
    Replies: 7
    Last Post: 01-29-2002, 03:41 PM