[comp.unix.programmer] problem with screen update optimization in curses

babin@IRO.UMontreal.CA (Gilbert Babin) (01/24/91)

I am currently writing a package using curses to implement simple
windowing objects, i.e. menu, submenu, dialogboxes, etc...

I developed part of it on VMS, but I'm trying to get the same result
on UNIX (SUN).  Unfortunately, when refreshing the screen in Unix,
it optimizes the flow of characters sent to the screen, which
does not occur under VMS, which will always completely refresh.

I tried using touchwin() before refreshing evry window, but for
each window update the 3 or 4 layered windows flicker.  This
becomes annoying when it occurs every time you type a character...

Is there any way to go around this optimization without having
the screen flickering, and without having to redraw each
window every time it has to be refreshed?

--
-----------------------------------------------------------------------
Gilbert Babin			Rensselaer Polytechnic Institute
babin@iro.umontreal.CA		Decision Sciences & Engineering Systems
(514)382-3863			Troy, NY, USA, 12180-3590

allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) (01/24/91)

As quoted from <1991Jan23.202536.1406@IRO.UMontreal.CA> by babin@IRO.UMontreal.CA (Gilbert Babin):
+---------------
| on UNIX (SUN).  Unfortunately, when refreshing the screen in Unix,
| it optimizes the flow of characters sent to the screen, which
| does not occur under VMS, which will always completely refresh.
| I tried using touchwin() before refreshing evry window, but for
| each window update the 3 or 4 layered windows flicker.  This
| becomes annoying when it occurs every time you type a character...
+---------------

Depends on the version of SunOS.  If you have a version with System V
libraries, use the System V curses:  it has two ways of optimizing output.
Sufficiently recent versions of the BSD curses may also possess one of these
mechanisms.

The first way of doing this is to use delayed refresh.  Refresh each window by
calling wnoutrefresh(win), then call doupdate() when you're done; this allows
curses to optimize *between* the window refreshes, and thereby do no output
for obsured parts of windows.

The second, which is fairly recent and likely not to be in the BSD-style
curses that is probably the default on SunOS, is to use echochar().  This
function is used exactly like addch(), but it sends output to the screen
*immediately* if other refresh operations are not needed.  It bypasses the
refresh() mechanism when it can, so output is very rapid.  (wechochar(win, ch)
is the version used on windows other than stdscr.)

If neither is available, you're stuck unless you hand-optimize by only
refreshing the current window and letting pending refreshes to other windows
sit until you absolutely need them.  Unfortunately, if you *do* want
"background updates" of partially visible windows, you're stuck.  (This is why
the wnoutrefresh()/doupdate() mechanism was developed.)

++Brandon
-- 
Me: Brandon S. Allbery			    VHF/UHF: KB8JRR on 220, 2m, 440
Internet: allbery@NCoast.ORG		    Packet: KB8JRR @ WA8BXN
America OnLine: KB8JRR			    AMPR: KB8JRR.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery    Delphi: ALLBERY