Curses (programming library)
Encyclopedia
curses is a terminal
Computer display
A monitor or display is an electronic visual display for computers. The monitor comprises the display device, circuitry, and an enclosure...

 control library
Library (computer science)
In computer science, a library is a collection of resources used to develop software. These may include pre-written code and subroutines, classes, values or type specifications....

 for Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 systems, enabling the construction of text user interface
Text user interface
TUI short for: Text User Interface or Textual User Interface , is a retronym that was coined sometime after the invention of graphical user interfaces, to distinguish them from text-based user interfaces...

 (TUI) applications.

The name is a pun on the term “cursor
Cursor (computers)
In computing, a cursor is an indicator used to show the position on a computer monitor or other display device that will respond to input from a text input or pointing device. The flashing text cursor may be referred to as a caret in some cases...

 optimization”. It is a library of functions that manage an application's display on character-cell terminals (e.g., VT100
VT100
The VT100 is a video terminal that was made by Digital Equipment Corporation . Its detailed attributes became the de facto standard for terminal emulators.-History:...

).

Overview

The curses API is described in several places. Most implementations of curses use a database that can describe the capabilities of thousands of different terminals. There are a few implementations, such as PDCurses, which use specialized device drivers rather than a terminal database. Most implementations use terminfo
Terminfo
Terminfo is a library and database that enables programs to use display terminals in a device-independent manner. This library has its origins in the UNIX System III operating system....

; some use termcap
Termcap
Termcap is a software library and database used on Unix-like computers. It enables programs to use display computer terminals in a device-independent manner, which greatly simplifies the process of writing portable text mode applications...

. Curses has the advantage of back-portability to character-cell terminals and simplicity. For an application that does not require bit-mapped graphics or multiple fonts, an interface implementation using curses will usually be much simpler and faster than one using an X
X Window System
The X window system is a computer software system and network protocol that provides a basis for graphical user interfaces and rich input device capability for networked computers...

 toolkit.

Using curses, programmers are able to write text-based applications without writing directly for any specific terminal type. The curses library on the executing system sends the correct control characters based on the terminal type. It provides an abstraction of one or more windows that maps onto the terminal screen. Each window is represented by a character matrix. The programmer sets up each window to look as they want the display to look, and then tells the curses package to update the screen. The library determines a minimal set of changes needed to update the display and then executes these using the terminal's specific capabilities and control sequences.

In short, this means that the programmer simply creates a character matrix of how the screen should look and lets curses handle the work.

History

The first curses library was written by Ken Arnold
Ken Arnold
Kenneth Cutts Richard Cabot Arnold is an American computer programmer well known as one of the developers of the 1980s dungeon-crawling computer game Rogue, for his contributions to the original Berkeley distribution of Unix, for his books and articles about C and C++ Kenneth Cutts Richard Cabot ...

 and originally released with BSD
Berkeley Software Distribution
Berkeley Software Distribution is a Unix operating system derivative developed and distributed by the Computer Systems Research Group of the University of California, Berkeley, from 1977 to 1995...

 UNIX, where it was used for several games, most notably Rogue
Rogue (computer game)
Rogue is a dungeon crawling video game first developed by Michael Toy and Glenn Wichman around 1980. It was a favorite on college Unix systems in the early to mid-1980s, in part due to the procedural generation of game content. Rogue popularized dungeon crawling as a video game trope, leading...

.
The name "curses" is a pun on cursor optimization. Sometimes it is incorrectly stated that curses was used by the vi
Vi
vi is a screen-oriented text editor originally created for the Unix operating system. The portable subset of the behavior of vi and programs based on it, and the ex editor language supported within these programs, is described by the Single Unix Specification and POSIX.The original code for vi...

 editor
Source code editor
A source code editor is a text editor program designed specifically for editing source code of computer programs by programmers. It may be a standalone application or it may be built into an integrated development environment ....

. In fact the code in curses that optimizes moving the cursor from one place on the screen to another was borrowed from vi
Vi
vi is a screen-oriented text editor originally created for the Unix operating system. The portable subset of the behavior of vi and programs based on it, and the ex editor language supported within these programs, is described by the Single Unix Specification and POSIX.The original code for vi...

, which predated curses.

Curses was originally implemented using the termcap
Termcap
Termcap is a software library and database used on Unix-like computers. It enables programs to use display computer terminals in a device-independent manner, which greatly simplifies the process of writing portable text mode applications...

 library. A few years later, Mark Horton
Mary Ann Horton
Mary Ann Horton, formerly Mark R. Horton , is a Usenet and Internet pioneer. Horton contributed to Berkeley UNIX , including the vi editor and terminfo database, and led the growth of Usenet in the 1980s....

, who had made improvements to the vi
Vi
vi is a screen-oriented text editor originally created for the Unix operating system. The portable subset of the behavior of vi and programs based on it, and the ex editor language supported within these programs, is described by the Single Unix Specification and POSIX.The original code for vi...

 and termcap
Termcap
Termcap is a software library and database used on Unix-like computers. It enables programs to use display computer terminals in a device-independent manner, which greatly simplifies the process of writing portable text mode applications...

 sources at Berkeley
University of California, Berkeley
The University of California, Berkeley , is a teaching and research university established in 1868 and located in Berkeley, California, USA...

, went to AT&T
AT&T
AT&T Inc. is an American multinational telecommunications corporation headquartered in Whitacre Tower, Dallas, Texas, United States. It is the largest provider of mobile telephony and fixed telephony in the United States, and is also a provider of broadband and subscription television services...

 and made a different version using terminfo
Terminfo
Terminfo is a library and database that enables programs to use display terminals in a device-independent manner. This library has its origins in the UNIX System III operating system....

, which became part of UNIX System III
UNIX System III
UNIX System III was a version of the Unix operating system released by AT&T's Unix Support Group . It was first released outside of Bell Labs in 1982. UNIX System III was a mix of various AT&T Unixes: PWB/UNIX 2.0, CB UNIX 3.0, UNIX/TS 3.0.1 and UNIX/32V...

 and UNIX System V
UNIX System V
Unix System V, commonly abbreviated SysV , is one of the first commercial versions of the Unix operating system. It was originally developed by American Telephone & Telegraph and first released in 1983. Four major versions of System V were released, termed Releases 1, 2, 3 and 4...

. Due to licensing restrictions on the latter, the BSD and AT&T versions of the library were developed independently. In addition to the termcap/terminfo improvement, other improvements were made in the AT&T version:
video highlighting (bold, underline): The BSD version supported only standout.
line-drawing: The BSD version gave little support here.
colors: This was not anticipated in the BSD version.

AT&T curses development appears to have halted in the mid-1990s when X/Open Curses was defined.

However, development of ncurses
Ncurses
ncurses is a programming library that provides an API which allows the programmer to write text user interfaces in a terminal-independent manner. It is a toolkit for developing "GUI-like" application software that runs under a terminal emulator...

 and PDCurses
PDCurses
PDCurses is a public domain curses programming library for DOS, Windows, X11 and SDL. While development of the original curses library halted in the mid-1990s, the development of ncurses and PDcurses continued. PDcurses implements most of the functions available in the original X/Open and System V...

 continues. A version of BSD curses continues to be maintained in the NetBSD
NetBSD
NetBSD is a freely available open source version of the Berkeley Software Distribution Unix operating system. It was the second open source BSD descendant to be formally released, after 386BSD, and continues to be actively developed. The NetBSD project is primarily focused on high quality design,...

 operating system (wide character support, termcap to terminfo migration, etc).

pcurses and PDcurses

Some improvements were made to the BSD library in the 1990s as "BSD 4.4" curses, e.g., to provide more than one type of video highlighting. However, those are not widely used. Rather, a different line of development started by imitating the AT&T curses, from at least two implementations: pcurses by Pavel Curtis
Pavel Curtis
Pavel Curtis is an American software architect at Microsoft who is best known for having founded and managed LambdaMOO, an online community...

 (started in 1982) and PDCurses (Public Domain curses) by Mark Hessling to support his editor THE
The Hessling Editor
The Hessling Editor is one of the older open source text editor projects...

 (started in 1987).

ncurses

ncurses (new curses) "originated as pcurses ... and was re-issued as ncurses 1.8.1 in late 1993".
ncurses is the most widely known implementation of curses, and has motivated further development of other variations, such as BSD curses in the NetBSD
NetBSD
NetBSD is a freely available open source version of the Berkeley Software Distribution Unix operating system. It was the second open source BSD descendant to be formally released, after 386BSD, and continues to be actively developed. The NetBSD project is primarily focused on high quality design,...

 project.

Portability

Although the ncurses library was initially developed under Linux, OpenBSD, FreeBSD, and NetBSD it has been ported to many other ANSI/POSIX UNIX systems, mainly by Thomas Dickey. PDCurses, while not identical to ncurses, uses the same function calls and operates the same way as ncurses does except that PDCurses targets different devices, e.g., console windows for DOS
DOS
DOS, short for "Disk Operating System", is an acronym for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions 95, 98, and Millennium Edition.Related...

, Win32, OS/2
OS/2
OS/2 is a computer operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively. The name stands for "Operating System/2," because it was introduced as part of the same generation change release as IBM's "Personal System/2 " line of second-generation personal...

, as well as X11. Porting between the two is not difficult. For example, the roguelike
Roguelike
The roguelike is a sub-genre of role-playing video games, characterized by randomization for replayability, permanent death, and turn-based movement. Most roguelikes feature ASCII graphics, with newer ones increasingly offering tile-based graphics. Games are typically dungeon crawls, with many...

 game ADOM
Ancient Domains of Mystery
Ancient Domains of Mystery, or ADOM, is a roguelike game by Thomas Biskup first released in . The player's aim is to stop the forces of Chaos that invade the world of Ancardia....

was written for Linux and ncurses, later ported to DOS and PDCurses.

Screen shot

Below are some typical examples of curses (in a terminal window which supports colour) - used for the tin
Tin (newsreader)
tin is an open source text-based and threaded news client, used to read and post messages on the USENET global communications network.-History:...

 and a CD processing product.

Curses-based software

Curses-based software is software whose user interface
User interface
The user interface, in the industrial design field of human–machine interaction, is the space where interaction between humans and machines occurs. The goal of interaction between a human and a machine at the user interface is effective operation and control of the machine, and feedback from the...

 is implemented through the Curses library, or a compatible library (such as Ncurses
Ncurses
ncurses is a programming library that provides an API which allows the programmer to write text user interfaces in a terminal-independent manner. It is a toolkit for developing "GUI-like" application software that runs under a terminal emulator...

).

Curses is designed to facilitate GUI-like functionality on a text-only device, such as a PC running in console mode, a hardware ANSI terminal, a Telnet
TELNET
Telnet is a network protocol used on the Internet or local area networks to provide a bidirectional interactive text-oriented communications facility using a virtual terminal connection...

 or SSH
Secure Shell
Secure Shell is a network protocol for secure data communication, remote shell services or command execution and other secure network services between two networked computers that it connects via a secure channel over an insecure network: a server and a client...

 client, or similar.

Curses-based programs often have a user interface that resembles a traditional graphical user interface, including 'widgets
Widget (computing)
In computer programming, a widget is an element of a graphical user interface that displays an information arrangement changeable by the user, such as a window or a text box. The defining characteristic of a widget is to provide a single interaction point for the direct manipulation of a given...

' such as text boxes and scrollable lists, rather than the command line interface (CLI) most commonly found on text-only devices. This can make them more user-friendly than a CLI-based program, while still being able to run on text-only devices. Curses-based software can also have a lighter resource footprint and operate on a wider range of systems (both in terms of hardware and software) than their GUI-based counterparts. This includes old pre-1990 machines along with modern embedded systems using text-only displays.

Curses was used in the implementation of a language called FMLI, which was used to present a user friendly textual interface called FACE in SVR4 systems, to provide basic systems administration functionality. FMLI based upon Curses was later also used in Solaris, to provide an interface for higher level functionality, for commands surrounding Live Upgrade.

However, not all Curses-based software employs a text user interface
Text user interface
TUI short for: Text User Interface or Textual User Interface , is a retronym that was coined sometime after the invention of graphical user interfaces, to distinguish them from text-based user interfaces...

 which resembles a graphical user interface. One counterexample would be the popular vi
Vi
vi is a screen-oriented text editor originally created for the Unix operating system. The portable subset of the behavior of vi and programs based on it, and the ex editor language supported within these programs, is described by the Single Unix Specification and POSIX.The original code for vi...

 text editor, which while not being CLI-based, uses memorized keyboard commands almost exclusively, rather than the prompting TUI
Text user interface
TUI short for: Text User Interface or Textual User Interface , is a retronym that was coined sometime after the invention of graphical user interfaces, to distinguish them from text-based user interfaces...

/GUI style, which relies more on recognition than recall.

Curses is most commonly associated with Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 operating systems, although implementations for Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 also exist.

See also

  • conio
    Conio.h
    conio.h is a C header file used in old MS-DOS compilers to create text user interfaces. It is not described in The C Programming Language book, and it is not part of the C standard library, ISO C nor is it defined by POSIX....

     – a similar idea, for DOS
    DOS
    DOS, short for "Disk Operating System", is an acronym for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions 95, 98, and Millennium Edition.Related...

  • S-Lang – an interpreted language with some related features
  • SMG$
    SMG$
    SMG$ is a library of screen management routines for OpenVMS. These routines allow programs to create text-based, terminal interfaces in a terminal-independent manner. This is similar in concept to the ncurses library made popular under UNIX....

     – a similar idea, for OpenVMS
    OpenVMS
    OpenVMS , previously known as VAX-11/VMS, VAX/VMS or VMS, is a computer server operating system that runs on VAX, Alpha and Itanium-based families of computers. Contrary to what its name suggests, OpenVMS is not open source software; however, the source listings are available for purchase...


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK