Programming with curses

The curses library is a subroutine library for terminal-independent screen painting and input-event handling. The curses library gives you a high-level screen model, while hiding the differences between terminal types. It automatically optimizes output to change one screenful of text into another.

The curses library uses a database format called terminfo, which describes the capabilities of thousands of different terminals.

ncurses

The Interix Software Development Kit (SDK) implementation of the curses library is ncurses. The original documentation for ncurses, which was written by Eric S. Raymond and Zeyd M. Ben-Halim, has been shortened and modified to reflect the Interix implementation. For more information about curses, see Writing programs with ncurses.

The ncurses library is a freeware implementation of the System V curses application programming interface (API), with some clearly marked extensions. It includes the following System V curses features:

This implementation also uses the insert-line, delete-line, and character features, and determines how to optimally use these features with no help from the programmer. It allows arbitrary combinations of video attributes, even on terminals that leave "magic cookies" on the screen to mark changes in attributes.

Terminology

The following terminology is used with some consistency:

window
A data structure that describes a subrectangle of the screen. It can be as large as the entire screen. You can write to a window as though it were a miniature screen, scrolling independently of other windows on the physical screen.
screen
A subset of window, which can be as large as the terminal screen. That is, one can start at the upper left-hand corner and encompass the lower right-hand corner. One of these, stdscr, is automatically provided.
terminal screen
What is currently being displayed by the terminal; that is, what the user sees now. This is a special screen.

Where to begin

If you are unfamiliar with curses, it is recommended that you read about curses here and also read the more complete documentation, Writing programs with ncurses. If you are an experienced curses programmer, it is recommended that you read Debugging, Compatibility with older versions, and Hints, tips, and tricks. These topics will provide you with background information on the special features of the ncurses implementation.

This section covers: