Date: Sun, 22 Jun 1997 09:11:55 +0200 (SAT) From: Robert Nordier <rnordier@iafrica.com> To: un_x@anchorage.net (Steve Howe) Cc: questions@FreeBSD.ORG Subject: Re: ncurses Message-ID: <199706220711.JAA03964@eac.iafrica.com> In-Reply-To: <Pine.BSF.3.95q.970621185035.8932A-100000@aak.anchorage.net> from Steve Howe at "Jun 21, 97 06:53:21 pm"
next in thread | previous in thread | raw e-mail | index | archive | help
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 <ncurses.h> #include <string.h> #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 */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199706220711.JAA03964>