[comp.unix.sysv386] Curses and color

rr@sco.COM (Ronald Joe Record) (01/31/91)

staceyc@sco.COM (Stacey Campbell) writes:


|In article <1991Jan17.064429.13943@vpnet.chi.il.us> jimr@vpnet.chi.il.us (Jim Rendant) writes:

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

|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;
| <deleted Stacey's code>
==========================================================================

Here's something similar to what staceyc posted which in addition saves
and restores the "graphics" and "inverse" mode color attributes. I usually
call save_colors() just prior to initscr() and rest_colors() after endwin()
and just prior to exiting the application. The routine has_colors() is
a curses routine so this is only meant to be linked into a curses app.

#include <curses.h>
#include <sys/console.h>

static int cur_tty[3] = { -1, -1, -1 };

save_colors() {

	if (has_colors() == TRUE) {
		cur_tty[0] = ioctl( 0, GIO_ATTR, 0);
		printf( "\033[7m" );
		fflush( stdout );
		cur_tty[1] = ioctl( 0, GIO_ATTR, 0);
		printf( "\033[12m" );
		fflush( stdout );
		cur_tty[2] = ioctl( 0, GIO_ATTR, 0);
		printf( "\033[10;0m" );
	}
}

rest_colors() {

	if (has_colors() == TRUE) {
		if (cur_tty[0] != -1)
		{
			printf( "\033[=%dF\033[=%dG",
				(cur_tty[0])&0x0f, ((cur_tty[0])&0xf0)>>4);
		}
		if (cur_tty[1] != -1)
		{
			printf( "\033[=%dH\033[=%dI",
			(cur_tty[1])&0x0f, ((cur_tty[1])&0xf0)>>4);
		}
		if (cur_tty[2] != -1)
		{
			printf( "\033[=%dJ\033[=%dK",
			(cur_tty[2])&0x0f, ((cur_tty[2])&0xf0)>>4);
		}
	}
}

-- 

"A boy without mischief is like a bowling ball without a liquid center."
                                                       --Homer Simpson

mhoffos@janus.mtroyal.ab.ca (03/16/91)

Does anyone out in the wide world of this newsgroup have any source that
displays text in color using curses/terminfo?  I am trying to get (*ahem*)
nethack 3p10 to use color -- the hooks are all in there, but it seems not to
work in Esix.

Using strings, I found a call in libcurses.a that indicates if the terminal can
display colors (has_color()).  It is true if the statement "colors#" is in the
terminfo for a terminal.  Any ideas?  Does anyone have a terminfo for the
console of a SYSV386 machine that they know works for color display using
curses?

If worse comes to worse, I can always hard-code the \033f;bm sequenece into the
output, but I would rather not.

Mike Hoffos
--
mhoffos@janus.mtroyal.ab.ca
(Mount Royal College is a community college in Calgary, Alberta)

Disclaimer:     Mount Royal College doesn't speak for me, and I *certainly*
                don't speak for it.

cjeffery@cs.arizona.edu (Clinton Jeffery) (03/19/91)

From article <1991Mar15.091313.7322@janus.mtroyal.ab.ca>, by mhoffos@janus.mtroyal.ab.ca:
> Does anyone out in the wide world of this newsgroup have any source that
> displays text in color using curses/terminfo?  I am trying to get (*ahem*)
> nethack 3p10 to use color -- the hooks are all in there, but it seems not to
> work in Esix.

I got it to work by hacking the code that sends the color info...I had to
swap two things that were being set, because ESIX couldn't handle it in
the order nethack is setting them.  It is really the case that a simple
edit to a couple printf's did the trick, and that finding the problem and
fixing it took a couple afternoons for me since I didn't know where to look.
I have them on tape somewhere if you are really stumped.  I absolutely love
Nethack, but it is a perfect embodiment of itself--it is a total hack.
-- 
| Clint Jeffery, U. of Arizona Dept. of Computer Science
| cjeffery@cs.arizona.edu -or- {noao allegra}!arizona!cjeffery
--

grant@bluemoon.uucp (Grant DeLorean) (03/23/91)

mhoffos@janus.mtroyal.ab.ca writes:

>Does anyone out in the wide world of this newsgroup have any source that
>displays text in color using curses/terminfo?  I am trying to get (*ahem*)
>nethack 3p10 to use color -- the hooks are all in there, but it seems not to
>work in Esix.

 Don't feel bad, I haven't gotten it to use color under ISC (2.2 or 2.21)
and we are not the only ones. I started with 3.0i PL8, no joy on the color
yet. The rest works great though. 

-- 
\  Grant DeLorean  (grant@bluemoon)    {n8emr|nstar}!bluemoon!grant  /
"You need only reflect that one of the best ways to get yourself a reputation 
as a dangerous citizen these days is to go about repeating the very phrases
which our founding fathers used in the struggle for independence."-C.A. Beard

kayvan@satyr.UUCP (Kayvan Sylvan) (03/26/91)

You have to use ``color'' and ``standout'' in your NETHACKOPTIONS. If
you're using the Console device, make sure your TERM is at386 and not
at386-m (the default) and you can also use the ``IBMgraphics'' keyword
in your NETHACKOPTIONS line.

This all works in nh3p9 at least.

			---Kayvan
-- 
| Kayvan Sylvan       Unix/C, GNU tools   879 Lewiston Drive   408-978-1407  |
| Sylvan Associates   GUIs, Databases     San Jose, CA 95136  Think Globally |
|                     Networking, X       apple!satyr!kayvan   Act Locally   |
| === Currently looking for contracts === Hire me now! Avoid the rush! ===   |