Next: 8.5 Windows Up: 8 Character Cell Graphics Previous: 8.3 Ncurses - Introduction

# 8.4 Initializing

- `WINDOW *initscr()`
  This is the first function usually called from a program using ncurses. In some cases it is useful to call slk_init(int), filter(), ripoffline(...) or use_env(bf) before initscr(). When using multiple terminals (or perhaps testing capabilities), you can use newterm(...) instead of initscr().

  initscr() will read the proper terminfo file and initialize the ncurses data structures, allocate memory for and and set and to the values the terminal has. It will return a pointer to or ERR when an error has occured. You don't need to initialize the pointer with:

  initscr() will do this for you. If the return value is ERR, your program should exit because no ncurses function will work:

- `SCREEN *newterm(char *type, FILE *outfd, FILE *infd)`
  For multiple terminal output call newterm(...) for every terminal you would access with ncurses instead of initscr(). `type` is the name of the terminal as contained in $TERM (ansi, xterm, vt100, for example), `outfd` is the output pointer and `infd` is the pointer used for input. Call endwin() for every terminal opened with newterm(...).
- `SCREEN *set_term(SCREEN *new)`
  With set_term(SCREEN) you can switch the current terminal. All functions will affect the current terminal which is set with set_term(SCREEN).
- `int endwin()`
  endwin() will do the cleanup, restore the terminal modes in the state they had before calling initscr() and move the cursor to the lower left corner. Don't forget to close all opened windows before you call endwin() to exit your program.

  An additional call to refresh() after endwin() will restore the terminal to the status it had before calling initscr() (visual-mode) otherwise it will be cleared (non-visual-mode).

- `int isendwin()`
  Returns TRUE if endwin() was called with a following refresh(), otherwise FALSE.
- `void delscreen(SCREEN* sp)`
  After endwin() call delscreen(SCREEN) to free up all occupied resources, when SCREEN is no longer needed. (Note: not implemented yet.)

Next: 8.5 Windows Up: 8 Character Cell Graphics Previous: 8.3 Ncurses - Introduction