Initializing curses

This section describes the commands used for initializing curses.

Use the following commands to initialize curses:

Command Description
endwin Terminates the curses subroutine libraries and their data structures
initscr Initializes the curses subroutine library and its data structures
isendwin Returns TRUE if the endwin subroutine has been called without any subsequent calls to the wrefresh subroutine
newterm Sets up a new terminal
setupterm Sets up the TERMINAL structure for use by curses
You must include the curses.h file at the beginning of any program that calls curses subroutines. To do this, use the following statement:
#include <curses.h>

Before you can call subroutines that manipulate windows or screens, you must call the initscr or newterm subroutine. These subroutines first save the terminal's settings and then call the setupterm subroutine to establish a curses terminal.

If you need to temporarily suspend curses, use a shell escape or subroutine. To resume after a temporary escape, call the wrefresh or doupdate subroutine. Before exiting a curses program, you must call the endwin subroutine. The endwin subroutine restores tty modes, moves the cursor to the lower-left corner of the screen, and resets the terminal into the proper nonvisual mode.

Most interactive, screen-oriented programs require character-at-a-time input without echoing the result to the screen. To establish your program with character-at-a-time input, call the cbreak and noecho subroutines after calling the initscr subroutine. When accepting this type of input, programs should also call the following subroutines:
  • nonl subroutine.
  • intrflush subroutine with the Window parameter set to the stdscr and the Flag parameter set to FALSE. The Window parameter is required but ignored. You can use stdscr as the value of the Window parameter, because stdscr is already created for you.
  • keypad subroutine with the Window parameter set to the stdscr and the Flag parameter set to TRUE.

The isendwin subroutine is helpful if, for optimization reasons, you do not want to call the wrefresh subroutine needlessly. To determine if the endwin subroutine was called without any subsequent calls to the wrefresh subroutine, use the isendwin subroutine.