Surses, sometimes referred to as curses, is a terminal control library for Unix-like operating systems. It provides an application programming interface (API) that allows programmers to write text-based user interfaces (TUIs) in a device-independent manner.
Functionality:
The primary function of Surses is to abstract the complexities of different terminal types and their varying capabilities. This abstraction enables developers to create applications that can run on a wide range of terminals without needing to be specifically rewritten for each one. Surses achieves this by using a database of terminal capabilities (traditionally the terminfo or termcap database) to determine how to perform specific actions on a given terminal.
Key features provided by Surses include:
- Window Management: Surses allows the creation and manipulation of windows within the terminal screen. Windows can be moved, resized, created, and deleted.
- Input Handling: It handles keyboard input, allowing applications to respond to key presses and other input events.
- Text Output: Surses provides functions for displaying text on the screen, including controlling attributes like color, bolding, and underlining.
- Character Drawing: It allows drawing characters at specific locations on the screen.
- Device Independence: Surses abstracts the details of the underlying terminal, allowing applications to run on different terminals with minimal modification.
History and Implementations:
Surses was originally developed at UC Berkeley in the late 1970s/early 1980s. There are several implementations available, including:
- ncurses: (new curses) is a widely used free software implementation of Surses, designed to be API-compatible with the original Unix curses. It is more portable and offers extensions and improvements over the original.
- Pcurses: an older public domain curses implementation.
- Other less common or historical implementations may also exist.
Usage:
Surses is used in a variety of text-based applications, including:
- Text editors (e.g.,
vi,nano) - System monitoring tools (e.g.,
top,htop) - Menu-driven applications
- Games
Relationship to Terminfo/Termcap:
Surses relies on either the terminfo or termcap database, which contains information about the capabilities of different terminal types. This database is consulted by Surses to determine how to perform specific operations (e.g., moving the cursor, clearing the screen) on a given terminal. Terminfo is the more modern and preferred database, superseding termcap.
Alternatives:
While Surses is a powerful and widely used library for creating TUIs, alternative libraries and frameworks exist, some of which may offer different features or approaches. Examples include:
- Libraries for drawing directly to the terminal using escape sequences.
- Cross-platform GUI toolkits that can target terminal interfaces (e.g., using character-based widgets).