Curses (programming library)

Last updated
curses
Developer(s) Ken Arnold
Initial release1978 [1]
Written in C
Type Widget toolkit

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

Contents

The name 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). [2]

Overview

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 the desired appearance of each window, then tells the curses package to update the screen. The library determines a minimal set of changes that are 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.

The curses API is described in several places. [3] 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.

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 . [4] [5] [6] Some improvements were made to the BSD library in the 1990s as "4.4BSD" curses, e.g., to provide more than one type of video highlighting.[ citation needed ] However, those are not widely used.

The name "curses" is a pun on cursor optimization. [7] 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. [5]

According to Goodheart, Ken Arnold's original implementation of curses started by reusing functions from the termcap library, and adding to that. [8] A few years later, Mary Ann Horton, who had maintained the vi and termcap sources at Berkeley, went to AT&T Corporation and made a different version using terminfo, which became part of UNIX System III and UNIX System V. 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 supported in the BSD version.

AT&T curses development appears to have halted in the mid-1990s when X/Open Curses was defined. [9] In 1995, BSD maintainer, Keith Bostic, officially deprecated the curses library in favor of ncurses. [10] [ dubious ] Development of ncurses and PDCurses continues. A version of BSD curses continues to be maintained in the NetBSD operating system (wide character support, termcap to terminfo migration, etc.).

pcurses and PDCurses

Different lines of development started by imitating the AT&T curses, from at least three implementations: pcurses by Pavel Curtis (started in 1982), PDCurses (Public Domain curses) by Mark Hessling to support his editor THE (started in 1987) as well as Rexx/Curses, [11] and PC curses (version 1.4 and earlier by Bjorn Larsson-based inspired by Pavel Curtis' library before 1990.) [12] [13] [ discuss ]

ncurses

ncurses (new curses) "originated as pcurses ... and was re-issued as ncurses 1.8.1 in late 1993". [14] 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. [15] [16]

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. [17] [18]

Screenshots

Applications

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 or SSH client, or similar. Curses-based software is software whose user interface is implemented through the curses library, or a compatible library (such as ncurses).

Curses-based programs often have a user interface that resembles a traditional graphical user interface, including 'widgets' 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 is most commonly associated with Unix-like operating systems, although implementations for Microsoft Windows also exist.

See also

Related Research Articles

<span class="mw-page-title-main">Cygwin</span> Unix subsystem for Windows machines

Cygwin is a Unix-like environment and command-line interface for Microsoft Windows. Cygwin's purpose is expressed in its motto: "Get that Linux feeling – on Windows".

ncurses Text-based user interface API

ncurses is a programming library providing an application programming interface (API) that allows the programmer to write text-based user interfaces (TUI) in a terminal-independent manner. It is a toolkit for developing "GUI-like" application software that runs under a terminal emulator. It also optimizes screen changes, in order to reduce the latency experienced when using remote shells.

<span class="mw-page-title-main">Operating system</span> Software that manages computer hardware resources

An operating system (OS) is system software that manages computer hardware and software resources, and provides common services for computer programs.

vi (text editor) Keyboard-oriented text editor

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.

<span class="mw-page-title-main">ANSI escape code</span> Method used for display options on video text terminals

ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals and terminal emulators. Certain sequences of bytes, most starting with an ASCII escape character and a bracket character, are embedded into text. The terminal interprets these sequences as commands, rather than text to display verbatim.

<span class="mw-page-title-main">Computer terminal</span> Computer input/output device for users

A computer terminal is an electronic or electromechanical hardware device that can be used for entering data into, and transcribing data from, a computer or a computing system. The teletype was an example of an early-day hard-copy terminal and predated the use of a computer screen by decades. Starting in the mid-1970s with machines such as the Sphere 1, Sol-20, and Apple I, terminal circuitry began to be integrated into personal and workstation computer systems, with the computer handling character generation and sometimes outputting to a basic CRT display such as a consumer TV.

<span class="mw-page-title-main">Text-based user interface</span> Type of interface based on outputting to or controlling a text display

In computing, text-based user interfaces (TUI), is a retronym describing a type of user interface (UI) common as an early form of human–computer interaction, before the advent of bitmapped displays and modern conventional graphical user interfaces (GUIs). Like modern GUIs, they can use the entire screen area and may accept mouse and other inputs. They may also use color and often structure the display using box-drawing characters such as ┌ and ╣. The modern context of use is usually a terminal emulator.

tin (newsreader)

tin is an open-source, text-based, threaded newsreader, used to read and post messages on Usenet, the worldwide distributed discussion system.

<span class="mw-page-title-main">Pseudoterminal</span>

In some operating systems, including Unix and Linux, a pseudoterminal, pseudotty, or PTY is a pair of pseudo-device endpoints (files) which establish asynchronous, bidirectional communication (IPC) channel between two or more processes. The master provides means by which a terminal emulator process controls the slave. The slave emulates a hardware text terminal device. PTY are similar to bidirectional pipes.

nvi Re-implementation of ex/vi

nvi is a re-implementation of the classic Berkeley text editor, ex/vi, traditionally distributed with BSD and, later, Unix systems. It was originally distributed as part of the Fourth Berkeley Software Distribution (4BSD).

Filesystem in Userspace (FUSE) is a software interface for Unix and Unix-like computer operating systems that lets non-privileged users create their own file systems without editing kernel code. This is achieved by running file system code in user space while the FUSE module provides only a bridge to the actual kernel interfaces.

In computer networking, STREAMS is the native framework in Unix System V for implementing character device drivers, network protocols, and inter-process communication. In this framework, a stream is a chain of coroutines that pass messages between a program and a device driver. STREAMS originated in Version 8 Research Unix, as Streams.

A console application or command-line program is a computer program designed to be used via a text-only user interface, such as a text terminal, the command-line interface of some operating systems or the text-based interface included with most graphical user interface (GUI) operating systems, such as the Windows Console in Microsoft Windows, the Terminal in macOS, and xterm in Unix.

<span class="mw-page-title-main">Ken Arnold</span> American computer programmer (born 1958)

Kenneth Cutts Richard Cabot Arnold is an American computer programmer well known as one of the developers of the 1980s dungeon-crawling video game Rogue, for his contributions to the original Berkeley (BSD) distribution of Unix, for his books and articles about C and C++, and his high-profile work on the Java platform.

<span class="mw-page-title-main">Terminfo</span>

Terminfo is a library and database that enables programs to use display terminals in a device-independent manner. Mary Ann Horton implemented the first terminfo library in 1981–1982 as an improvement over termcap. The improvements include

<span class="mw-page-title-main">Termcap</span>

Termcap is a legacy software library and database used on Unix-like computers that enables programs to use display computer terminals in a device-independent manner, which greatly simplifies the process of writing portable text mode applications. It was superseded by the terminfo database used by ncurses, tput, and other programs.

In computing, tput is a standard Unix operating system command which makes use of terminal capabilities.

<span class="mw-page-title-main">Command-line interface</span> Computer interface that uses text

A command-line interface (CLI) is a means of interacting with a computer program by inputting lines of text called command-lines. Command-line interfaces emerged in the mid-1960s, on computer terminals, as a user-friendly alternative to punched cards.

The POSIX terminal interface is the generalized abstraction, comprising both an application programming interface for programs, and a set of behavioural expectations for users of a terminal, as defined by the POSIX standard and the Single Unix Specification. It is a historical development from the terminal interfaces of BSD version 4 and Seventh Edition Unix.

In computing and telecommunications, the capabilities of a terminal are various terminal features, above and beyond what is available from a pure teletypewriter, that host systems can make use of. They are (mainly) of control codes and escape codes that can be sent to or received from the terminal. The escape codes sent to the terminal perform various functions that a CRT terminal is capable of, but that a teletypewriter is not; such as moving the terminal's cursor to positions on the screen, clearing and scrolling all or parts of the screen, turning on and off attached printer devices, programming programmable function keys, changing display colours and attributes, and setting display title strings. The escape codes received from the terminal signify things such as function key, arrow key, and other special key keystrokes.

References

  1. Craddock, David L. (June 17, 2016). "Procedural Dungeons of Doom: The Making of Rogue – Chapter 3" . Retrieved May 18, 2023.
  2. Thomas E. Dickey. "NCURSES - Frequently Asked Questions".
  3. John Strang, Programming with curses, O'Reilly, ISBN   0-937175-02-1
  4. Peter H. Salus (October 1994). "The history of Unix is as much about collaboration as it is about technology". Byte.
  5. 1 2 Arnold, K. C. R. C. (1977). "Screen Updating and Cursor Movement Optimization: A Library Package". University of California, Berkeley.{{cite journal}}: Cite journal requires |journal= (help)
  6. Kenneth C. R. C. Arnold; Elan Amir (December 1992). "Screen Updating and Cursor Movement Optimization: A Library Package".
  7. Thomas E. Dickey. "NCURSES - Frequently Asked Questions".
  8. Goodheart, Berny (1991). UNIX Curses Explained. Prentice Hall. p. xi. ISBN   0-13-931957-3.
  9. "X/Open Curses, Issue 4 Version 2, Reference Pages". The Open Group. 1997.
  10. Eric S. Raymond (September 1, 1995). "ncurses: Portable Screen-Handling for Linux". Linux Journal . Retrieved May 18, 2023.
  11. Mark Hessling (2008). "Rexx/Curses". SourceForge project rexxcurses. Retrieved 2014-02-10.
  12. F. Ellermann (1993-07-26). "CURSES.NEW in pccurses.zip" . Retrieved 2014-02-10. based on PC curses (version 1.4) written by Bjorn Larsson[ permanent dead link ]
  13. Bjorn Larsson (1990-01-14). "README.NOW in pccurs14.zip". Archived from the original on 2014-02-23. Retrieved 2014-02-10. PCcurses is a port/rewrite of Pavel Curtis' [package]
  14. Thomas E. Dickey (December 1996). "NCURSES - New Curses".
  15. NetBSD project (February 2004). "CURSES_SCREEN(3), NetBSD Library Functions Manual".
  16. Ruibiao Qiu (September 2005). "NetBSD-SoC: Wide Character Support in NetBSD curses Library".
  17. Thomas Biskup (1994–2007). "ADOM - The Past". Archived from the original on 2007-10-10. Retrieved 2007-11-16.
  18. Thomas Biskup (March 15, 1996). "New Game: ADOM (MS-DOS, MS-Windows, and Linux only)". Newsgroup:  rec.games.roguelike.announce . Retrieved 2007-11-16.