[sco.opendesktop] CURSES & COLOR windows

staceyc@sco.COM (Stacey Campbell) (01/29/91)

In article <1991Jan17.064429.13943@vpnet.chi.il.us> jimr@vpnet.chi.il.us (Jim Rendant) writes:
>I have been working with SCO UNIX V3.2.2 and the curses packages. My question
>is, Once I have set my colors using init_pair() then doing a wattron(); how can
>I clear a window changing the entire window to the colors I defined using
>init_pair()?

Color attributes are treated the same as other curses attributes,
i.e. on a character by character basis.  Changing an entire window
will involve setting that attribute for each character in the window.
Expensive but true.

>Are ther any tips for using curses and color windows, pads etc...

If I absolutely must have a window with a background color different
to the defined original pair (usually black bg), I write a window
creation routine around newwin() which sets the given COLOR_PAIR
attribute then writes spaces to the entire window, then leaves those
color attributes on when the routine is exited.  You will still have
to deal with restoring those color attributes if they are changed later
for the given window.  Curses does provide some general purpose routines
and macros to help.

Note that in the standard Unix 3.2 curses library wstandend(win) is
equivalent to wattset(win, A_NORMAL), which means that amongst other
things any set color attributes will be clobbered.

You will also note that after running a terminfo curses color application
on a SCO Unix console that the default screen attributes will be set
to the terminfo "op" entry.  This may not correspond to what you have
setup with the setcolor command.  Here is a little bit of code that will
restore the setcolor fg and bg colors after a color curses application
has been run;

/*
 * Gets/sets console colors that would otherwise be reset to
 * black and white by a curses color application.
 */


#include <stdio.h>
#include <signal.h>

#define GIO_ATTR  ('a' << 8) | 0	/* Ioctl call for current attribute */

static void SetColor();

int main(argc,argv)

int argc;
char *argv[];

{
	int cur_attr;

	(void)signal(SIGINT, SIG_IGN);
	(void)signal(SIGQUIT, SIG_IGN);
	if (argc == 1)
	{
		cur_attr = ioctl(0, GIO_ATTR, 0);
		if (cur_attr == -1)
			printf("not console\n");
		else
			printf("%x\n", cur_attr);
	}
	else
	{
		if (sscanf(argv[1], "%x", &cur_attr) != 1)
			exit(1);
		SetColor(cur_attr & 0x0F, (cur_attr >> 4) & 0x0F);
		exit(0);
	}

	return 0;
}

static void SetColor(forecolor, backcolor)

int forecolor, backcolor;

{
	printf("\033[=%dF", forecolor);
	printf("\033[=%dG", backcolor);
	printf("\033[0m");
	fflush(stdout);
}

Usage is;

:
saved_colors="not console"
if [ "$TERM" = "ansi" ]
then
	saved_colors=`conscolor`
fi
...run application...
if [ $saved_colors != "not console" ]
then
	conscolor $saved_colors
fi
-- 
                             Stacey Campbell       
                        Internet: staceyc@sco.com
     UUCP: {uunet,ucscc,att,sq,altos,lotus,sun,microsoft}!sco!staceyc