Thread: Colour printing in ncurses

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    16

    Colour printing in ncurses

    I'm writing some stuff using a text based interface. I've decided to go with PDCurses, which essentially is curses for the windows DOS prompt. It mimics the traditional ncurses api in all aspects. Though I am having trouble with printing colours. I can print colours fine onto the STDSCR window, although I cannot print to any other window in colour.

    Here is an example. If you are on a UNIX based system change the header to ncurses.h

    Code:
    int main(int argc, char *argv[])
    {
             initscr();
    
    	if(has_colors() == FALSE)
    	{
                    endwin();
    		printf("Your terminal does not support color\n");
    		exit(1);
    	}
    
    	start_color();
    	init_pair(1, COLOR_RED, COLOR_BLACK);
    
    	WINDOW *testwin = newwin (10, 10, 0, 0);
    	box (testwin, 0, 0);
    	wrefresh (testwin);
    
            attron (COLOR_PAIR (1));
    	mvwprintw (testwin, 0, 0, "%s", "Hello");
    	attroff (COLOR_PAIR (1));
    
    	wrefresh (testwin);
    }

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    attron() works on stdscr. If you want to set attributes for a specific window, use wattron(). This use of of ‘w’ for a specific window is the general behavior of curses—note how you had to use wrefresh() instead of refresh() on testwin. Of course there are exceptions, but that's curses for you.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    16
    Yes, I just came across it in the tutorial I was using. It never mentioned that function before agh, oh well, thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Printing Problem
    By silverlight001 in forum C# Programming
    Replies: 0
    Last Post: 03-23-2009, 01:13 AM
  2. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  3. Ncurses colours without allocating colour pairs?
    By kzar in forum C Programming
    Replies: 12
    Last Post: 04-17-2005, 11:55 AM
  4. DirectDraw colour matching
    By Hunter2 in forum Game Programming
    Replies: 2
    Last Post: 12-10-2002, 02:17 PM
  5. Colour theory... (weird title)
    By Magos in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2001, 04:16 PM