[net.unix-wizards] Need help with curses

keith@enmasse.UUCP (Keith Crews) (05/07/86)

I am a curses novice and am trying to get a program that came
over the net (the game of reversi) to work properly.  The problem
is that the screen flashes whenever a window is updated.  The program
uses 5 non-overlapping windows.  It frequently calls wclear() for a
particular window, puts some info in that window, and then calls
wrefresh() to update the screen.  This causes the entire screen
to be erased and redrawn, rather than just that window.  If the wclear
call is not made, then the flash goes away but the screen gets
garbled.  The program
below is a simple case that exhibits the problem and is based on
the code in reversi.  Please respond by mail and I will post the
answer if it seems to be of general interest.

It seems to me that the problem could be in several areas:

	1)  bug in program
	2)  bug in curses
	3)  missing terminfo entries that curses needs to
	    do the right thing
	4)  terminal is too dumb to ever do the right thing
	5)  this is what it is supposed to do
	6)  other

I am running system V on a 68000.  It is the official Motorola port
of AT&T system V.  I am using a wyse 50 terminal.  terminfo is used
by this curses rather than termcap.  The only other curses-
like program that we have on the system is vi, which works fine.
The program is compiled with cc -o test test.c -lcurses -ltermlib
Thanks in advance!

		Keith Crews


#include <curses.h>
#include <signal.h>
#include <setjmp.h>
#include <sys/types.h>
#include <sys/times.h>
WINDOW	*w1, *w2;
main ()
{
	int finish_up (), i;
	initscr();
	initwindows();
	for (i = 0; i < 2; i++) {
		message(w1, "window 1 %d", i);
		sleep(1);
		message(w2, "window 2 %d", i);
		sleep(1);
	}
	finish_up ();
}
finish_up ()
{
	endwin();
	exit (0);
}
initwindows()
{
	w1 = newwin(3,30,2,10); /* 3 lines, 30 cols, start at line 2, col 10 */
	w2 = newwin(3,30,12,10); /* 3 lines, 30 cols, start at line 12, col 10*/
}
message(w, f, a1)
	WINDOW * w;
	char * f;
	int a1;
{
	wclear(w);
	wprintw(w, f, a1);
	wrefresh(w);
}

zellich@almsa-1.arpa (Rich Zellich) (05/13/86)

We had the same problem when moving some code from a VAX running BSD 4.2
to a couple of microcomputer versions of UNIX.  The solution in our case
was simply to change wclear calls to werase calls.  wclear will always
cause the screen to be cleared, even when it shouldn't, on certain brain-
damaged curses implementations, and werase never does (wclear is stated to
clear the screen only when the window in question is the whole screen,
but it just doesn't work that way; werase does not set the clear-screen
flag at all, and turned out to be safe in all cases we have encountered
so far).

Cheers,
Rich