DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Basic ETI programming

The routines initscr, refresh, endwin

The routines initscr, refresh, and endwin initialize a terminal screen to an ``in ETI state,'' update the contents of the screen, and restore the terminal to an ``out of ETI state,'' respectively. Consider the simple program introduced earlier and reproduced in ``The purposes of initscr, refresh, and endwin in a program''.

   #include <ocurses.h>
   

main() { initscr(); /* initialize terminal settings and ocurses.h data structures and variables */

move( LINES/2 - 1, COLS/2 - 4 ); addstr("Bulls"); refresh(); /* send output to (update) terminal screen */ addstr("Eye"); refresh(); /* send more output to terminal screen */ endwin(); /* restore all terminal settings */ }

The purposes of initscr, refresh, and endwin in a program

An ETI program usually starts by calling initscr; your program should call initscr only once. This routine uses the environment variable $TERM to determine what terminal is being used. (See ``The ETI/terminfo connection'' for details.) It then initializes all the declared data structures and other variables from ocurses.h. For example, initscr would initialize LINES and COLS for the sample program on whatever terminal it was run. If the Teletype 5425 were used, this routine would initialize LINES to 24 and COLS to 80. Finally, this routine writes error messages to stderr and exits if errors occur.

During the execution of the program, output and input is handled by routines like move and addstr in the sample program. For example,

   move( LINES/2 - 1, COLS/2 - 4 );
says to move the cursor to the left of the middle of the screen. The line
   addstr("Bulls");
says to write the character string Bulls. For example, if the Teletype 5425 were used, these routines would position the cursor and write the character string at (11,36).


NOTE: All ETI routines that move the cursor move it from its home position in the upper left corner of a screen. The (LINES,COLS) coordinate at this position is (0,0) not (1,1). Notice that the vertical coordinate is given first and the horizontal second, which is the opposite of the common 'x,y' order of screen (or graph) coordinates. The -1 in the sample program takes the (0,0) position into account to place the cursor on the center line of the terminal screen.

Routines like move and addstr do not actually change a physical terminal screen when they are called. The screen is updated only when refresh is called after one or more windows (internal representations of the screen) are updated. This is a very important concept, which we discuss below under ``More about refresh and windows''.

Finally, an ETI program ends by calling endwin. This routine restores all terminal settings and positions the cursor at the lower left corner of the screen.


Next topic: Compiling an ETI program
Previous topic: The header files

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004