From owner-freebsd-questions Sun Jun 22 00:16:49 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id AAA15902 for questions-outgoing; Sun, 22 Jun 1997 00:16:49 -0700 (PDT) Received: from eac.iafrica.com (196-31-98-177.iafrica.com [196.31.98.177]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id AAA15894 for ; Sun, 22 Jun 1997 00:16:44 -0700 (PDT) Received: (from rnordier@localhost) by eac.iafrica.com (8.8.5/8.6.12) id JAA03964; Sun, 22 Jun 1997 09:11:57 +0200 (SAT) From: Robert Nordier Message-Id: <199706220711.JAA03964@eac.iafrica.com> Subject: Re: ncurses In-Reply-To: from Steve Howe at "Jun 21, 97 06:53:21 pm" To: un_x@anchorage.net (Steve Howe) Date: Sun, 22 Jun 1997 09:11:55 +0200 (SAT) Cc: questions@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL31 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-questions@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk Steve Howe wrote: > > i color with ncurses working ok? > i have my own windowing C > routines, but am looking for > some portable way to print in color. > > ncurses just seems to make my screen black & white, > no matter what colors i choose, no matter what color > my ttyv? was previously. Color works fine. Try the example below. -- Robert Nordier #include #include #define rightstr(s, n) ((s) + sizeof(s) - (n) - 1) #define spaces(n) rightstr(spcstr, n) #define ATTR_BACK 0 #define ATTR_TEXT 1 chtype attrib[2] = { A_NORMAL, A_REVERSE }; static char spcstr[132]; static void clearwin(WINDOW * win); int main(void) { memset(spcstr, ' ', sizeof(spcstr)); initscr(); start_color(); cbreak(); noecho(); nonl(); if (has_colors()) { init_pair(1, COLOR_WHITE, COLOR_BLUE); attrib[ATTR_BACK] = COLOR_PAIR(1); init_pair(2, COLOR_RED, COLOR_GREEN); attrib[ATTR_TEXT] = COLOR_PAIR(2); } wattrset(stdscr, attrib[ATTR_BACK]); clearwin(stdscr); wattrset(stdscr, attrib[ATTR_TEXT]); mvaddstr((LINES - 2) / 2, (COLS - 12) / 2, "Hello World!"); move(LINES - 1, 0); getch(); wclear(stdscr); refresh(); endwin(); return 0; } static void clearwin(WINDOW * win) { int y, x, i; getmaxyx(win, y, x); if (y == LINES) y--; for (i = 0; i < y; i++) mvwaddstr(win, i, 0, spaces(x)); } /* end */