Colour printing in ncurses

This is a discussion on Colour printing in ncurses within the C Programming forums, part of the General Programming Boards category; I'm writing some stuff using a text based interface. I've decided to go with PDCurses, which essentially is curses for ...

  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
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    983
    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, 07: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, 01:17 PM
  5. Colour theory... (weird title)
    By Magos in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2001, 03:16 PM

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