Termcap

Last updated
Termapi.svg

Termcap (terminal capability) 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.

Contents

Bill Joy wrote the first termcap library in 1978 [1] [2] for the Berkeley Unix operating system; it has since been ported to most Unix and Unix-like environments, even OS-9. [3] Joy's design was reportedly influenced by the design of the terminal data store in the earlier Incompatible Timesharing System. [4] [ better source needed ][ dubious ]

A termcap database can describe the capabilities of hundreds of different display terminals. This allows programs to have character-based display output, independent of the type of terminal. On-screen text editors such as vi and Emacs are examples of programs that may use termcap. Other programs are listed in the Termcap category.

Examples of what the database describes:

Data model

Termcap databases consist of one or more descriptions of terminals.

Indices

Each description must contain the canonical name of the terminal. It may also contain one or more aliases for the name of the terminal. The canonical name or aliases are the keys by which the library searches the termcap database.

Data values

The description contains one or more capabilities, which have conventional names. The capabilities are typed: boolean, numeric and string. The termcap library has no predetermined type for each capability name. It determines the types of each capability by the syntax:

Applications which use termcap do expect specific types for the commonly used capabilities, and obtain the values of capabilities from the termcap database using library calls that return successfully only when the database contents matches the assumed type.

Hierarchy

Termcap descriptions can be constructed by including the contents of one description in another, suppressing capabilities from the included description or overriding or adding capabilities. No matter what storage model is used, the termcap library constructs the terminal description from the requested description, including, suppressing or overriding at the time of the request.

Storage model

Termcap data is stored as text, making it simple to modify. The text can be retrieved by the termcap library from files or environment variables.

Environment variables

The TERM environment variable contains the terminal type name.

The TERMCAP environment variable may contain a termcap database. It is most often used to store a single termcap description, set by a terminal emulator to provide the terminal's characteristics to the shell and dependent programs.

The TERMPATH environment variable is supported by newer termcap implementations and defines a search path for termcap files.

Flat file

The original (and most common) implementation of the termcap library retrieves data from a flat text file. Searching a large termcap file, e.g., 500 kB, can be slow. To aid performance, a utility such as reorder is used to put the most frequently used entries near the beginning of the file.

Hashed database

4.4BSD based implementations of termcap store the terminal description in a hashed database (e.g., something like Berkeley DB version 1.85). These store two types of records: aliases which point to the canonical entry, and the canonical entry itself. The text of the termcap entry is stored literally.

Limitations and extensions

The original termcap implementation was designed to use little memory:

Newer implementations of the termcap interface generally do not require the two-character name at the beginning of the entry.

Capability names are still two characters in all implementations.

The tgetent function used to read the terminal description uses a buffer whose size must be large enough for the data, and is assumed to be 1024 characters. Newer implementations of the termcap interface may relax this constraint by allowing a null pointer in place of the fixed buffer, [5] or by hiding the data which would not fit, e.g., via the ZZ capability in NetBSD termcap. [6] The terminfo library interface also emulates the termcap interface, and does not actually use the fixed-size buffer.

The terminfo library's emulation of termcap allows multiple other entries to be included without restricting the position. A few other newer implementations of the termcap library may also provide this ability, though it is not well documented. [7]

Obsolete features

A special capability, the "hz" capability, was defined specifically to support the Hazeltine 1500 terminal, which had the unfortunate characteristic of using the ASCII tilde character ('~') as a control sequence introducer. [8] [ discuss ] In order to support that terminal, not only did code that used the database have to know about using the tilde to introduce certain control sequences, but it also had to know to substitute another printable character for any tildes in the displayed text, since a tilde in the text would be interpreted by the terminal as the start of a control sequence, resulting in missing text and screen garbling. [9] Additionally, attribute markers (such as start and end of underlining) themselves took up space on the screen.[ citation needed ] Comments in the database source code often referred to this as "Hazeltine braindamage". [10] Since the Hazeltine 1500 was a widely used terminal in the late 1970s,[ citation needed ] it was important for applications to be able to deal with its limitations.

See also

Related Research Articles

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">Unix shell</span> Command-line interpreter for Unix operating system

A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting language, and is used by the operating system to control the execution of the system using shell scripts.

<span class="mw-page-title-main">Terminal emulator</span> Program that emulates a video terminal

A terminal emulator, or terminal application, is a computer program that emulates a video terminal within some other display architecture. Though typically synonymous with a shell or text terminal, the term terminal covers all remote terminals, including graphical interfaces. A terminal emulator inside a graphical user interface is often called a terminal window.

<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.

curses (programming library) Terminal control library enabling construction of text user interfaces

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

The archiver, also known simply as ar, is a Unix utility that maintains groups of files as a single archive file. Today, ar is generally used only to create and update static library files that the link editor or linker uses and for generating .deb packages for the Debian family; it can be used to create archives for any purpose, but has been largely replaced by tar for purposes other than static libraries. An implementation of ar is included as one of the GNU Binutils.

<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.

Capability-based security is a concept in the design of secure computing systems, one of the existing security models. A capability is a communicable, unforgeable token of authority. It refers to a value that references an object along with an associated set of access rights. A user program on a capability-based operating system must use a capability to access an object. Capability-based security refers to the principle of designing user programs such that they directly share capabilities with each other according to the principle of least privilege, and to the operating system infrastructure necessary to make such transactions efficient and secure. Capability-based security is to be contrasted with an approach that uses traditional UNIX permissions and Access Control Lists.

<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.

<span class="mw-page-title-main">Comparison of command shells</span>

A command shell is a command-line interface to interact with and manipulate a computer's operating system.

In computing, ioctl is a system call for device-specific input/output operations and other operations which cannot be expressed by regular file semantics. It takes a parameter specifying a request code; the effect of a call depends completely on the request code. Request codes are often device-specific. For instance, a CD-ROM device driver which can instruct a physical device to eject a disc would provide an ioctl request code to do so. Device-independent request codes are sometimes used to give userspace access to kernel functions which are only used by core system software or still under development.

ND-NOTIS was a office automation suite by Norsk Data introduced in the early 80s, running on the SINTRAN III platform on both ND-100 and ND-500 architectures. It was also available on Microsoft Windows running in networks of Norsk Data servers.

<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

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

In Unix-like operating systems, a device file or special file is an interface to a device driver that appears in a file system as if it were an ordinary file. There are also special files in DOS, OS/2, and Windows. These special files allow an application program to interact with a device by using its device driver via standard input/output system calls. Using standard system calls simplifies many programming tasks, and leads to consistent user-space I/O mechanisms regardless of device features and functions.

<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.

Capsicum is an implementation of capability-based security for UNIX and similar systems. Presented at USENIX 2010, the system is part of FreeBSD since its 9.0 release. It has also been adapted to DragonflyBSD in the form of kernel patches.

References

  1. Peter H. Salus, "The history of Unix is as much about collaboration as it is about technology", Byte, October 1994.
  2. Kenneth C. R. C. Arnold and Elan Amir, "Screen Updating and Cursor Movement Optimization: A Library Package"
  3. Joel Mathew Hegberg (November 1994). "Tackling Termcap, Part I". OS-9/OSK Answers!. Retrieved 26 April 2021.
  4. Mark Crispin (7 Oct 1998). "Re: KL Console Commands". Newsgroup:  alt.sys.pdp10.
  5. The GNU Termcap Library
  6. NetBSD termcap file format
  7. Discussion of termcap in vi
  8. termcap(5)    BSD File Formats Manual
  9. Stallman, Richard M. (1992). "The Termcap Library and Database, Second Edition". Gnu.org. Retrieved 17 May 2014.
  10. "termcap.src". Apple Computer. Retrieved 17 May 2014.