curses (programming library)

From Wikipedia, the free encyclopedia

Jump to: navigation, search

curses is a terminal control library for Unix-like systems, enabling the construction of text user interface (TUI) applications.

curses is a pun on the term "cursor optimization". It is a library of functions that manage an application's display on character-cell terminals (e.g., VT100).[1]

Contents

[edit] History

The first curses library was written by Ken Arnold and originally released with BSD UNIX, where it was used for several games, most notably Rogue. [2] [3] [4]

The name "curses" is a pun on cursor optimization.[5] Sometimes it is incorrectly stated that curses was used by the vi editor. In fact the code in curses that optimizes moving the cursor from one place on the screen to another was borrowed from vi, which predated curses.[3]

curses was originally implemented using the termcap library.[citation needed] A few years later, Mark Horton, who had made improvements to the vi and termcap sources at Berkeley, went to AT&T and made a different version using terminfo, which became part of UNIX System III. Due to licensing restrictions on the latter, the BSD and UNIX versions of the library were developed independently. In addition to the termcap/terminfo improvement, other improvements were made in the UNIX 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.

[edit] 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.[citation needed] However, those are not widely used. Rather, a different line of development started by imitating the UNIX curses, from at least two implementations: pcurses by Pavel Curtis (started in 1982) and PDCurses (Public Domain curses) by Mark Hessling to support his editor THE (started in 1987).

[edit] ncurses

ncurses (new curses) development started in 1991 or 1992 using pcurses and was first announced in 1993[6] as noted on the ncurses homepage. While development of ncurses and PDCurses continues, UNIX curses development appears to have halted in the mid-1990s when X/Open Curses was defined. [7] ncurses is the most widely known implementation of curses, and has motivated further development of other variations, such as BSD curses in the NetBSD project. [8] [9]

[edit] Overview

The curses API is described in several places.[10] 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, some use termcap. 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 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.

[edit] 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, Win32, OS/2, as well as X11. Porting between the two is not difficult. For example, the roguelike game ADOM was written for Linux and ncurses, later ported to DOS and PDCurses.[11][12]

[edit] See also

[edit] References

  1. ^ Thomas E. Dickey. "NCURSES - Frequently Asked Questions". http://invisible-island.net/ncurses/ncurses.faq.html. 
  2. ^ Peter H. Salus (October 1994). "The history of Unix is as much about collaboration as it is about technology". Byte. http://www.byte.com/art/9410/sec8/art3.htm. 
  3. ^ a b Arnold, K. C. R. C. (1977), Screen Updating and Cursor Movement Optimization: A Library Package., University of California, Berkeley 
  4. ^ Kenneth C. R. C. Arnold; Elan Amir (December 1992). ""Screen Updating and Cursor Movement Optimization: A Library Package". http://www.mirbsd.org/cman/manPSD/19.curses.htm. 
  5. ^ Thomas E. Dickey. "NCURSES - Frequently Asked Questions". http://invisible-island.net/ncurses/ncurses.faq.html#what_is_it. 
  6. ^ Thomas E. Dickey (December 1996). "NCURSES - New Curses". http://invisible-island.net/ncurses/. 
  7. ^ X/Open Curses "X/Open Curses, Issue 4 Version 2, Reference Pages". The Open Group. 1997. http://www.opengroup.org/onlinepubs/007908799/cursesix.html X/Open Curses. 
  8. ^ NetBSD project (February 2004). "CURSES_SCREEN(3), NetBSD Library Functions Manual". http://www.daemon-systems.org/man/curses_screen.3.html. 
  9. ^ Ruibiao Qiu (September 2005). "NetBSD-SoC: Wide Character Support in NetBSD curses Library". http://netbsd-soc.sourceforge.net/projects/wcurses/. 
  10. ^ John Strang, Programming with curses, O'Reilly, ISBN 0-937175-02-1
  11. ^ Thomas Biskup (1994-2007). "ADOM - The Past". http://www.adom.de/adom/past.php3. Retrieved on 2007-11-16. 
  12. ^ Thomas Biskup (March 15, 1996). "New Game: ADOM (MS-DOS, MS-Windows, and Linux only)". rec.games.roguelike.announce. (Web link). Retrieved on 2007-11-16.

[edit] External links

Personal tools