Curses: Drawing Boxes -- sending control chars

Dave Hammond daveh at marob.MASA.COM
Sat Aug 27 04:39:52 AEST 1988


In article <873 at wpg.UUCP> russ at wpg.UUCP (Russell Lawrence) writes:
>
>The curses box() function draws crude boxes around windows using ascii 
>characters like '|' and '-' that are passed to the function as 
>arguments.  By contrast, I'd like to write a better box drawing routine 
>that would take advantage of box drawing graphics capabilities on some 
>terminals.  Unfortunately, the terminfo definitions don't include any 
>parameters that would be appropriate, and the tic(1M) program won't 
>allow me to define new ones........................................... 

I was under the impression that terminfo-based curses allow characters
from an alternate characterset to be output (like line-drawing chars)
by or-ing them with A_ALTCHARSET.  Assuming that your terminal did graphics
by changing fonts and associating `characters' within that font with
graphics symbols, you should be able to say something like:

/* these are based on a vt100 */
#define GV 'x'
#define GH 'q'
(void) wbox(stdscr, GH | A_ALTCHARSET, GV | A_ALTCHARSET);

>............................  I figured I could get around the problem 
>by concocting a small database containing the command strings for the 
>various terminals we use in our office, but then I remembered that 
>curses functions won't allow me to send unadulterated control characters 
>to the terminal.  Can anybody suggest a work around?  

Note that the graphics capabilities GS (graphics start), GE (graphics end),
GH, GV and G1 thru G4 already exist in the /etc/termcap database.  If you're
so inclined (and your Curses doesn't already set them for you!), you could
find the appropriate strings there.

As far as curses allowing unadulterated contol characters in its output,
I believe that is version-dependent.  In many versions you must specifically
call unctrl(ch) to output the expanded string representation of control chars
(i.e. unctrl('\003') outputs `^C').

If you're gonna do this in a Curses program, but independent of Curses, you
must beware that you will get will get a box, but Curses will have no idea
that it is there and will step all over it.

If you try to output the box using Curses, you will have to send a
sequence of GS,GV,GE or GS,GH,GE for each component of the box. This
will cause Curses to think the graphics string takes as many line spaces
as there are bytes in the sequence and it will end up confused as to
where the end of the line is.

If you have access to terminfo, I suggest you use the A_ALTCHARSET
method. If not, you'll have to output the box using curses (so it knows
the thing is there), then overwrite it after EACH refresh() with your
own graphics box routine. This can make a LOT of extra terminal output.

Dave Hammond
  UUCP: {uunet|...}!masa.com!{dsix2|marob}!daveh
DOMAIN: dsix2!daveh at masa.com
------------------------------------------------------------------------------



More information about the Comp.unix.questions mailing list