|
|
As mentioned above, ETI routines do not update a terminal until refresh is called. Instead, they write to an internal representation of the screen called a window. When refresh is called, all the accumulated output is sent from the window to the current terminal screen.
A window acts a lot like a buffer does when you use a UNIX system editor. When you invoke vi(1), for instance, to edit a file, the changes you make to the contents of the file are reflected in the buffer. The changes become part of the permanent file only when you use the w or ZZ command. Similarly, when you invoke a screen program made up of ETI routines, they change the contents of a window. The changes become part of the current terminal screen only when refresh is called.
ocurses.h supplies a default window
named stdscr (standard screen),
which is the size of the current terminal's screen,
for all programs using ETI routines.
The header file defines stdscr to be of the type
WINDOW, a pointer to a
C structure which you might think of as a two-dimensional array
of characters representing a terminal screen.
The program always keeps track of what is on the physical screen,
as well as what is in
stdscr.
When refresh
is called,
it compares the two screen images
and sends a stream of characters to the terminal
that make the physical screen look like stdscr.
An ETI program considers many different ways to do this, taking
into account the various capabilities of the terminal
and similarities between what is on the screen
and what is on the window (stdscr).
It optimizes output by printing as few characters as is possible.
``The relationship between stdscr and a terminal screen (sheet 1 of 2)''
and
``The relationship between stdscr and a terminal screen (sheet 2 of 2)''
illustrate what happens when you execute the sample
ETI program that prints BullsEye
at the center of a terminal screen.
Notice in the figure that the terminal screen retains whatever garbage
is on it until the first refresh is called.
This refresh clears the screen and updates it with the current contents
of stdscr.
The relationship between stdscr and a terminal screen (sheet 1 of 2)
The relationship between stdscr and a terminal screen (sheet 2 of 2)
You can create other windows and use them instead of stdscr. Windows are useful for maintaining several different screen images. For example, many data entry and retrieval applications use two windows: one to control input and output and one to print error messages that do not mess up the other window. It is possible to subdivide a screen into many windows, refreshing each one of them as desired. And it is possible to create a window within a window; the smaller window is called a subwindow. See ``ETI windows'' for more information.