Curses! Graphics again!
Ross Oliver, x537, ionesco
rosso
Wed Nov 22 09:31:53 AEST 1989
In article <329 at usource.SARASOTA.FL.US> frankb at usource.SARASOTA.FL.US (Frank Bicknell) writes:
>In my original article <323 at usource.SARASOTA.FL.US> I mumbled:
>
>+ ...I've done some work at getting borders around windows that
>+ look more reasonable than:
>
>[ pretty box pictures deleted ]
>
>+ Almost every terminal we've seen these days supports
>+ character-mode graphics. ...
>+ Can anyone tell me if the newer versions of curses supplied with
>+ the new development system supports these characters? ...
>
>To date I've had no response: does anyone out there do anything
>with curses? If so, please drop me a line... I'd like to know
>more about the newer curses functionality.
In the SCO XENIX 2.3 and SCO UNIX 3.2 development systems, you can use
8-bit characters in curses. On the PC, and most terminals that use the
PC character set, the graphics characters are in the 128-to-255 range,
so you can use them directly to draw character graphics in curses. For
example, to draw a box around the window "w" using graphics characters
on the XENIX console, you could use the standard curses box() function:
box( w, '\263', '\304' );
There are two caveats that go with the box() function: the horizontal
and vertical elements must be single characters (not escape sequences),
and box() won't draw corners. You could draw the corner characters
after the box call, or write your own box function that includes putting
corner characters on boxes.
If you must support graphics elements that consist of more than one
character per screen position, you can use the new character mapping
functions of curses. These functions are described in the last section
of the Screen Processing chapter of the C Library Guide. They are
_not_ described in the curses manual entry.
These functions allow you to define your own mapping from the characters
curses outputs to what actually appears on the screen. If you have
the function mputch() defined in your program, then curses will call
your function instead of its normal output functions for each character
it sends to the screen. Using this method, you would assign arbitrary
single characters to your graphics elements, and your mputch() function
would map these to the multiple-character sequences needed by your
terminal. For example:
#define HORIZONTAL_CHAR '\200'
char *horizontal_sequence = '\033[x' /* characters needed by terminal to */
/* display an horizontal bar. */
#define VERTICAL_CHAR '\201'
char *vertical_sequence = '\033[y' /* characters needed by terminal to */
/* display a vertical bar. */
main()
{
initscr();
box( stdwin, HORIZONTAL_CHAR, VERTICAL_CHAR );
refresh();
...
}
mputch( ch );
{
switch( ch ) {
case HORIZONTAL_CHAR:
fputs( horizontal_sequence, stdout );
break;
case VERTICAL_CHAR:
fputs( vertical_sequence, stdout );
break;
default:
putc( ch, stdout );
}
}
----------------
In addition to the output mapping function, you can also define your
own function to handle special sequences (cursor motion, insert and
delete chars, etc), buffer flush, and initialization functions.
All of these functions are available for both the termcap and terminfo
versions of curses.
Ross Oliver
Technical Support
The Santa Cruz Operation, Inc.
More information about the Comp.unix.xenix
mailing list