Fact-checked by Grok 2 weeks ago

Termcap

Termcap is a legacy software library and database used on operating systems to describe the capabilities and control sequences of character-cell terminals and printers, enabling programs to adapt their display output in a terminal-independent manner. Developed by at the , it originated as a forerunner called "ttycap" in September 1977 and was first released in 1BSD in March 1978, before appearing in its standard form in 3BSD. The database is typically stored as an , such as /etc/termcap or /usr/share/misc/termcap, containing entries for specific models indexed by the TERM . Each entry consists of colon-separated fields beginning with one or more terminal names (e.g., vt100|vt102|DEC VT100 terminal), followed by capabilities categorized as flags (e.g., am for automatic margins), numeric values (e.g., co#80 for 80 columns), or string sequences (e.g., cl=\E[H\E[J for clearing the screen). These capabilities define behaviors like cursor movement, screen attributes, padding requirements for slow operations, and initialization/deinitialization sequences, supporting over 150 standardized features. Programs such as the vi editor, ex, tset, and early versions of the curses library access termcap via functions like tgetent to retrieve and compile these descriptions for runtime use. While influential in early Unix development, particularly in the Berkeley Software Distribution (BSD), termcap has been largely superseded by the more efficient database since System V Release 2.0 in 1983, though it persists for in modern systems.

Overview

Definition and Purpose

Termcap is a software library and associated database designed to describe the capabilities of various computer terminals, enabling programs to interact with terminal emulators in a device-independent manner. It provides a standardized way to define and query behaviors such as cursor positioning, screen erasure, and text attribute modifications like bold or reverse video, allowing applications to generate appropriate control sequences without embedding hardware-specific instructions. The primary purpose of Termcap is to promote portability in software that relies on terminal output, addressing the diversity of terminal hardware prevalent in early computing environments. By serving as an abstraction layer, it permits a single program to adapt its display logic to multiple terminal types—such as the VT100 or xterm—through runtime queries to the database, thereby reducing development effort and maintenance overhead for cross-terminal compatibility. This approach emerged in Unix systems during the 1970s to resolve the challenges posed by inconsistent terminal hardware, where developers at the University of California, Berkeley, needed a unified method to support varied devices without custom coding for each. For instance, a aiming to display a bold string can use Termcap's to retrieve the appropriate entry and exit sequences for emphasis mode from the database, apply them around the text, and output the result via the terminal's standard interface; this ensures the bold effect renders correctly on a using escape codes like [1m, while adapting seamlessly to xterm's similar but potentially variant implementation, all without altering the program's core logic.

Core Components

Termcap's core components revolve around the of terminal behaviors through structured entries that encapsulate and functional attributes. Each terminal entry begins with a canonical name, which serves as the primary , followed by one or more aliases separated by vertical bars (|) to accommodate variant or historical names for the same device. These names enable programs to reference the appropriate terminal without ambiguity. Beyond , the entry defines capabilities in three primary types: flags indicating the presence or absence of features (e.g., am for automatic margin wrapping, which signals if the terminal automatically advances to the next line upon reaching the right margin); numeric values specifying quantitative parameters (e.g., co#80 for 80 columns of screen width); and string values providing escape sequences or commands for specific actions (e.g., cm=\E[%i%d;%i%dH for moving the cursor to a given row and column using ANSI escape codes). The structure of each terminal entry is a colon-separated list of attribute-value pairs, where attributes are two-letter codes and values are either absent (for booleans, implying presence), suffixed with # followed by (for numerics), or literal strings potentially containing escape sequences (for strings). This format allows for a compact, human-readable representation of terminal features, with the canonical name and aliases in the initial field before the first colon, and capabilities following in subsequent fields. For instance, a simplified entry might appear as:
xterm|xterm-color|... :am:co#80:cm=\E[%i%d;%i%dH:...
This design facilitates extensibility while maintaining consistency across descriptions. Programs interact with these components via a standardized query interface provided by the Termcap library. Initialization occurs through the tgetent() function, which loads the entry for a specified terminal name from the database and returns 1 on success, 0 if no entry exists, or -1 on error. Subsequent retrieval uses specialized functions: tgetflag(id) returns 1 if the boolean capability id is present or 0 otherwise; tgetnum(id) returns the integer value for numeric capability id or -1 if absent; and tgetstr(id, area) retrieves the string for capability id, storing it in the provided buffer and returning a pointer to it. These functions enable applications to adapt output dynamically based on the terminal's described abilities, such as emitting appropriate escape sequences for cursor movement. Standard Termcap implementations support over 100 predefined capabilities, covering essential aspects like cursor control, screen clearing, and mode changes, as detailed in comprehensive references. Entries may also incorporate hierarchical inclusion by referencing another entry via the tc (use capabilities of) attribute, allowing inheritance of common features with overrides for specifics.

History

Origins and Development

Termcap originated from a forerunner called "ttycap," developed by in September 1977 while he was a graduate student at the . It was first released as ttycap in 1BSD in March 1978, and appeared in its standard form in 3BSD in December 1979, specifically to support the within the Berkeley Software Distribution (BSD) variant of Unix. created the system to enable portable screen management across diverse hardware, avoiding the need for terminal-specific code in applications like . The primary motivation arose from the proliferation of incompatible terminals during the 1970s era, when institutions like operated mixed environments with devices such as the Lear-Siegler alongside others lacking unified control sequences. At that time, no comprehensive standard like the later ANSI escape codes existed to normalize terminal behavior, compelling developers to address hardware variations manually. This diversity stemmed from the rapid growth in adoption, with vendors producing specialized video display units without interoperability in mind. The accompanying /etc/termcap database file in 3BSD included 81 entries describing various terminals' capabilities. These entries provided a foundational database for subsequent BSD releases, allowing programs to query and utilize terminal features dynamically through a simple library interface.

Adoption Across Systems

Following its introduction in the Berkeley Software Distribution (BSD) of Unix in 1978, Termcap rapidly spread to other Unix variants and influenced the development of terminal-handling software across diverse platforms. While AT&T's System V Unix Release 2.0 in 1984 replaced Termcap with the more efficient terminfo database for compiled terminal descriptions, many BSD-derived systems and hybrid implementations retained Termcap for compatibility, enabling portable screen-oriented applications in mixed environments. Termcap was ported beyond Unix to non-Unix operating systems, including , where the GNU implementation supported terminal-independent programming on DEC's VAX systems. Ports also appeared for and early PCs, facilitating the adaptation of Unix tools like editors and shells to PC environments through libraries that emulated terminal capabilities over serial connections. These efforts allowed developers to maintain cross-platform compatibility for applications requiring precise control of display terminals. The framework of Termcap significantly influenced the creation of full-screen applications in Unix ecosystems, such as the editor, which relied on Termcap entries to query and apply terminal-specific sequences for cursor and screen updates. Similarly, utilities like more for paginated text viewing and for process monitoring used Termcap to ensure consistent behavior across diverse terminals, establishing a foundation for terminal-agnostic software design that persisted into the . Although not formally standardized in POSIX.1 or POSIX.2, Termcap's core functions—such as tgetent for retrieving entries and tgoto for generating positioning strings—gained de facto portability through inclusion in system libraries, supporting interoperability in Unix-like systems without a unified specification. In the early 1990s, open-source projects extended Termcap's legacy; notably, ncurses version 1.8.1, released in November 1993, incorporated Termcap compatibility alongside terminfo support to address limitations in older terminals and enhance performance for modern applications.

Data Model

Terminal Capabilities

Terminal capabilities in Termcap represent the specific features and behaviors of a , allowing applications to adapt their output accordingly. These capabilities are essential for enabling portable, terminal-independent software that can query and utilize the terminal's attributes without hardcoding device-specific instructions. Each capability is identified by a unique two-letter code and is categorized into , numeric, or types, with over 200 standard capabilities documented across these categories. Boolean capabilities are flags that indicate the presence or absence of a particular feature, typically represented as a simple colon-separated entry in the Termcap database without additional values. For instance, the "am" capability signifies automatic margin wrapping, where the terminal automatically advances to the next line when the cursor reaches the right margin, preventing text from overwriting the edge. This type of is crucial for applications to determine if they need to manually handle line wrapping. Numeric capabilities provide integer values describing quantitative aspects of the terminal, such as dimensions or timing parameters, and are denoted with a "#" followed by the number. A representative example is the "" capability, which specifies the number of columns on the screen; for classic terminals like the , this is typically set to 80. These values help programs configure display layouts and avoid exceeding the terminal's physical limits. String capabilities consist of escape sequences or control strings that instruct the terminal to perform specific actions, often incorporating parameter formatting with "%" directives to insert variables like cursor positions. The "cm" capability, for cursor movement, exemplifies this: in ANSI-compatible terminals, it uses the sequence \E[%i%p1%d;%p2%dH to position the cursor at row %p1 and column %p2, where %i inserts the absolute row number if needed. String capabilities may also include padding information to address the timing requirements of slow terminals by specifying delays after certain operations, using the "$<" syntax to denote mandatory or optional pauses in milliseconds or character transmission times. For example, &#36;<5> inserts a 5-millisecond delay to ensure the terminal processes a command fully before the next output, mitigating issues like garbled displays on older hardware. This mechanism is particularly relevant for operations involving screen clears or attribute changes that require synchronization. Such strings enable precise control over screen elements like cursor navigation and text attributes.

Indices and Aliases

In the Termcap database, terminals are identified through a system of canonical names and aliases, which serve as unique keys for lookup and ensure compatibility across varying naming conventions used in applications. The canonical name is the primary, standardized identifier for a terminal type, typically a lowercase string that matches the value of the environment variable, such as "vt100" for the DEC terminal. This name is followed by one or more aliases separated by (|) characters, allowing multiple references to the same entry; for instance, the entry might begin with "vt100|vt100-am|ansi" to accommodate variations like "vt100-am" for the advanced video mode or "ansi" as a generic alias. These aliases enable flexible matching, as programs can specify any of the listed names without altering the underlying terminal description. Each Termcap entry commences with this name-alias list as the first field, delimited by colons (:) from subsequent capability fields, forming a single logical line that may span multiple physical lines using backslashes for continuation. The structure supports user-specifiable aliases beyond the canonical name and a verbose description, with the first name often limited to two characters in early designs for brevity, though modern implementations relax this constraint. This naming convention originated in the 1978 implementation by , prioritizing portability across diverse terminal hardware. The lookup process begins with the tgetent() function, which searches the database for a matching entry based on the provided name, typically derived from the environment variable. If the exact canonical name is not found, tgetent() falls back to checking aliases within each entry until a match is identified or the database is exhausted, returning a success code upon retrieval and storing the description in an internal buffer for further queries. The search prioritizes the environment variable if set, which can point to a specific file path or embed the full description inline; otherwise, it defaults to the system-wide /etc/termcap file. In the standard flat-file format, there is no formal index; tgetent() performs a linear scan through the file, comparing the query name against each entry's name-alias list sequentially, which can be inefficient for large databases but suffices for typical installations. To address performance issues in larger systems, some implementations, such as those in 4.4BSD-derived Unix variants, employ a hashed database format (e.g., using ) where entries are stored as keyed records, enabling constant-time lookups by name or alias. This hashed approach maintains with flat files while improving retrieval speed for environments with extensive terminal catalogs.

Hierarchical Structure

Termcap employs a hierarchical structure through the tc (terminal capability) field, which enables one terminal entry to inherit capabilities from another base entry. This is specified in the terminal description as :tc=base_term:, where base_term is the name of the referenced entry; the tc field must appear last in the description to ensure proper appending. Upon retrieval, the capabilities from the base entry are appended to the current entry, with any capabilities defined in the current entry overriding those in the base to allow customization. For instance, the vt220 entry uses :tc=vt100: to inherit basic capabilities from the vt100 description, while adding VT220-specific features like enhanced function keys and smoother scrolling. This inheritance mechanism reduces redundancy by building upon established descriptions for similar hardware, such as deriving the vt220 entry from vt100 via :tc=vt100:, which incorporates VT100 basics and overlays VT220-specific features like enhanced function keys and smoother scrolling. To prevent infinite recursion in chained inheritances, the original termcap limits expansion to up to 32 levels of tc references. This hierarchical approach was introduced in 4.1BSD in 1981 to efficiently manage descriptions for evolving terminal families, minimizing duplication in the database while supporting rapid adaptations for new models.

Storage and Retrieval

Environment Variables

Termcap utilizes several environment variables to facilitate efficient access to terminal capability data during runtime, allowing programs to determine and retrieve terminal descriptions without always relying on persistent storage. The primary variables are , , and TERMPATH, which enable quick in-memory lookups particularly valuable in resource-constrained or multi-user environments where file input/output operations were historically expensive. The TERM variable specifies the type of terminal in use, such as "vt100" for a Digital Equipment Corporation VT100 terminal. Programs set this via commands like export TERM=vt100, and the termcap library function tgetent() retrieves it using getenv("TERM") to identify and load the corresponding terminal entry from available sources. TERMCAP holds the complete termcap entry string for the terminal type indicated by TERM, enabling direct in-memory access that bypasses file reading for faster initialization, which is especially useful in embedded systems or custom configurations. If TERMCAP begins with a '/', it instead points to a specific termcap file; otherwise, its value serves as the raw description, limited to 1023 bytes of data plus a null terminator in the original implementation to fit the 1024-byte buffer required by tgetent(). This variable, introduced in 3BSD in 1979, allows overriding default entries and supports recursion chains for capability inheritance. TERMPATH defines a colon- or space-separated list of directories to search for termcap files when is used but TERMCAP does not provide a full description or file path; it defaults to $[HOME](/page/Home)/.termcap:/etc/termcap or /usr/share/misc/termcap if unset. Introduced in BSD 4.3 in 1986 to enhance portability and search flexibility, TERMPATH is ignored if TERMCAP specifies a full pathname. In typical usage, termcap-aware applications first check TERMCAP for an immediate description; if absent or invalid, they fall back to searching termcap files via and the paths in TERMPATH, optimizing startup by prioritizing in-memory data over disk access. This approach improves performance in scenarios where repeated file reads could slow multi-user systems.

Flat File Format

The Termcap flat consists of a plain text database where terminal descriptions are stored as colon-separated fields within logical lines, enabling programs to query terminal capabilities without embedding hardware-specific code. Developed by at the , this format originated in mid-1978 as part of efforts to standardize screen management across diverse terminals in early UNIX systems. Each entry represents a single terminal type and begins with a list of aliases separated by vertical bars (|), followed by capability definitions in the form cap=value or simply cap for booleans, all delimited by colons (:). (\) serve as escape characters to handle special cases, such as embedding colons within values (\:) or representing control characters (e.g., \E for escape). Entries can span multiple physical lines using a backslash at the end of a line to indicate continuation, with subsequent lines typically indented for readability. A representative example of a Termcap entry for a basic "dumb" terminal, which lacks advanced features and inherits from a base, illustrates the format's simplicity:
dumb|dumb terminal:
	:co#80:li#24:tc=[vt100](/page/VT100):
Here, co#80 specifies 80 columns (numeric ), li#24 indicates 24 lines, and tc=vt100 references another entry for inheritance, allowing shared without duplication. The entry starts at the left margin, and the trailing colon after the alias list marks the beginning of fields; empty fields (e.g., :bs: for ) are permitted to maintain structure. This design supports both short aliases for efficiency and verbose descriptions for clarity, with the last alias serving as the primary name. In traditional BSD systems, the master Termcap file is located at /etc/termcap, while distributions often place it at /usr/share/misc/termcap for shared access. These files typically range from 200 to 500 KB in size, encompassing hundreds of terminal entries to cover historical and contemporary . Parsing involves a linear of the file to match the TERM against aliases, followed by extraction and interpretation of capabilities, which can be inefficient for large databases but remains the default in many legacy and compatibility-focused systems despite its origins in 1978. Variable overrides via the TERMCAP environment can supplement file-based entries for runtime adjustments.

Hashed Database Implementation

The hashed database implementation for Termcap enhances performance by storing terminal capability entries in a hashed format, enabling rapid lookups without the need to parse an entire . Introduced in BSD 4.4 by developer Casey Leedom as part of the getcap library, this approach replaced the slower of flat files with constant-time access using ndbm-compatible storage. The database typically resides at paths like /usr/share/misc/termcap in BSD systems, built from source files such as termcap.src. In this structure, keys consist of canonical terminal names (e.g., ""), while values hold the complete capability strings, including expanded "tc=" (terminal capability) aliases to avoid runtime . The utility compiles the source into two files—often (directory index) and (data pages)—using ndbm or dbm formats for indexed retrieval via the getcap routines. This setup supports quick fetching of entries by name, bypassing full scans and handling hierarchical inclusions efficiently. Tools like makedb or in-memory hcreate can also generate similar hashed access, though is standard in BSD environments. The primary advantage is the reduction in lookup time from O(n) to average O(1), critical for systems with large databases exceeding 1000 entries, as it minimizes I/O and parsing overhead in applications like or curses-based programs. Adopted in for with BSD termcap libraries and in early distributions via termcap ports, it provided scalable storage for diverse terminal types without environment variable fallbacks. Version 1.85 of was later adapted in implementations around 2006 to overcome ndbm's 1024-byte record limits, allowing larger capability strings while maintaining . Though effective for its era, the hashed Termcap database has been largely supplanted by the more robust Terminfo format in modern Unix-like systems, persisting primarily in legacy BSD installations for backward compatibility.

Usage in Applications

Programmatic Access

Programmatic access to Termcap is provided through a C library API defined in the <termcap.h> header file, which includes functions such as tgetent, tgetflag, tgetnum, tgetstr, tgoto, and tputs for querying terminal capabilities and generating appropriate output sequences. The core workflow begins with initialization using the tgetent() function, which loads the terminal entry specified by the TERM environment variable from the Termcap database and returns 1 on success, 0 if no entry matches or the terminal type is invalid, and -1 if the database cannot be opened or read. In the original BSD implementation, tgetent requires a character buffer (typically 1024–2048 bytes) to store the entry; modern emulations like those in ncurses may ignore this buffer or allocate internally. Once initialized, applications retrieve capabilities using functions like tgetnum() for numeric values, tgetflag() for booleans, and tgetstr() for string capabilities, which also handles area pointer management for static buffer allocation. For tgetstr, the area parameter should point to writable memory to store the retrieved strings; passing NULL may cause crashes in original implementations but is handled by allocation in some modern versions. String capabilities retrieved by tgetstr(), such as the cursor addressing sequence "", often require parameterization and padding before output; this is achieved with tgoto() to substitute parameters (e.g., row and column positions) into the string, followed by tputs() to emit the result with appropriate delays based on the terminal's baud rate and the number of lines affected. The tputs() function takes the parameterized string, an affection count (typically 1 for single-line operations), and an output routine like putchar() to handle the actual writing to the terminal. Termcap supports auto-initialization in some implementations, allowing tgetstr() and related functions to implicitly call tgetent() if not already done, though explicit initialization is recommended for error handling. To integrate the Termcap library, programs are linked with -ltermcap, enabling portable terminal control in applications such as text editors (e.g., ) and shells, where it normalizes output across diverse hardware by expanding capability strings like "" for cursor positioning. The following example demonstrates retrieving and using the "" capability to move the cursor to a specific row and column, using buffers as required by the specification:
c
#include <termcap.h>

int main() {
    char termbuf[2048];  // Buffer for terminal entry
    char *ap = NULL;     // Area pointer for strings (will be set below)
    char strbuf[1024];   // Buffer for string capabilities
    ap = strbuf;
    char *cm;            // Cursor movement string
    int row = 10, col = 20;

    if (tgetent(termbuf, getenv("TERM")) != 1) {
        // Handle initialization error
        return 1;
    }

    cm = tgetstr("cm", &ap);
    if (cm == NULL) {
        // Handle missing capability
        return 1;
    }

    char *motion = tgoto(cm, col, row);
    tputs(motion, 1, putchar);

    return 0;
}
This snippet initializes the database into termbuf, fetches the "cm" string capability into strbuf via the area pointer, parameterizes it with tgoto(), and outputs it via tputs(), ensuring compatibility with terminals that support absolute cursor addressing. Note that in modern termcap emulations, buffers may not be strictly required.

Common Libraries and Tools

The original BSD curses library, developed by Ken Arnold and first released in 1979 as part of 3BSD, relied on Termcap for terminal-independent screen , enabling applications like the editor to handle cursor movement and display updates across diverse terminals. This integration allowed curses to abstract low-level terminal operations, such as outputting escape sequences for clearing the screen or positioning the cursor, by querying Termcap entries via functions like tgetstr and tputs. Ncurses, an open-source evolution of curses initiated by Thomas E. Dickey in 1993, maintains with Termcap through an emulation layer that leverages the more structured database internally. This compatibility mode supports the full Termcap API, including functions like tgetent for loading terminal descriptions and tgoto for generating parameterized strings, while adapting to 's extended features for broader terminal support. Ncurses handles a substantial overlap of capabilities between the two systems—approximately 200 shared entries for core operations like bold text (so) and underline (us)—ensuring legacy Termcap applications run without modification on modern systems. Several utilities facilitate Termcap entry management and testing within the ecosystem. The captoinfo tool converts Termcap source files to format, preserving capabilities like those for key mappings (e.g., kcub for ), while infotocap performs the reverse, outputting equivalent Termcap descriptions from entries. The tput command, originally from BSD and enhanced in implementations, queries individual capabilities such as (cursor positioning) for scripting, e.g., tput cup 10 20 to move the cursor to row 10, column 20, and supports Termcap names when entries are unavailable. Modern applications like Vim and incorporate Termcap as a fallback mechanism when is insufficient or unavailable, ensuring portability on older systems. In Vim, builtin Termcap entries provide default escape sequences for terminals without terminfo descriptions, such as xterm fallbacks for . similarly uses Termcap routines in its to initialize terminal modes, falling back to a compiled-in database if external files are missing. The GNU Readline library, used in tools like for line editing, integrates Termcap functions to retrieve capabilities such as (clear to end of line) from the terminal's entry, avoiding direct dependencies on curses while enabling interactive input handling. BSD derivatives like and continue full Termcap support through dedicated libraries and /etc/termcap files, with man pages documenting the for ongoing maintenance in legacy environments.

Limitations and Extensions

Design Constraints

Termcap was originally designed in the late 1970s for resource-constrained environments, such as the PDP-11 systems running early Berkeley Unix, where typical available RAM was under 64 KB for user programs. This led to stringent memory limitations in core functions like tgetent(), which retrieves terminal entries into a fixed-size to minimize dynamic allocation overhead and fit within the era's hardware constraints. A primary architectural constraint was the fixed 1024-byte for the TERMCAP or file entry, allowing a maximum of 1023 characters plus a null , which often caused for complex descriptions exceeding this limit. Capability naming further restricted extensibility, using only two-character codes from lowercase letters (e.g., cm for cursor movement), which provides a of 676 unique identifiers (26 letters squared), though only around 108 capabilities are defined in standard references like the , while offering no advanced support for parameterized strings beyond basic substitutions like %d for parameters. Performance was another inherent limitation, as tgetent() performs a through the entire termcap file (typically /etc/termcap) to match the terminal name from the TERM environment variable, resulting in slow lookups for large databases with hundreds of entries. Additionally, the format lacked built-in validation mechanisms, relying on applications to handle errors, which could lead to runtime failures if entries were malformed. Portability was hampered by the assumption of 7-bit ASCII encoding for all capabilities and strings, making it incompatible with international terminals using multibyte character sets before the advent of .

Modern Adaptations

Modern implementations of Termcap have addressed some of its original design limitations through extensions that enhance flexibility and compatibility with contemporary systems. One key adaptation is the removal of the traditional 1024-byte buffer limit in libraries like , which emulates Termcap using the more efficient database. Instead of relying on fixed-size buffers, dynamically allocates memory as needed for terminal entries, allowing support for longer capability strings without truncation or overflow errors. To handle overflows in entries exceeding the legacy size constraints, NetBSD's Termcap implementation introduces the "ZZ" capability, which points to an extended containing the full terminal description beyond the standard 1023-byte limit. This feature is only added for oversized entries to optimize space usage and is accessible via an alternate interface in compatible applications. Additionally, BSD 4.4 and later variants support multiple "tc=" (terminal capability) inclusions in a single entry, enabling depth-first traversal and concatenation of descriptions from referenced entries, similar to terminfo's model but without capability merging. Unicode support has been integrated into modern Termcap adaptations through extended escape sequences that align with UTF-8 encoding in terminals such as xterm-256color. When used in UTF-8 locales, these sequences allow capability strings to include multi-byte characters and rendering controls, ensuring proper display of international text without altering the core Termcap format. Linux distributions maintain Termcap libraries and databases, such as /etc/termcap, primarily for backward compatibility with legacy applications that do not support terminfo. Auto-conversion mechanisms in tools like ncurses' infocmp utility enable seamless translation of terminfo entries to Termcap format, facilitating hybrid environments. In the 2020s, Termcap remains actively maintained in FreeBSD, where it serves as the primary terminal database for tools like vi, and in embedded systems like those incorporating BusyBox, valued for its compact footprint in resource-constrained setups.

Relation to Terminfo

Key Differences

Terminfo was developed by Mary Ann Horton in 1981–1982 as a successor to termcap, aiming to address its limitations in efficiency and extensibility, and was included in Release 2 (SVR2) in 1984. This evolution marked a shift toward a more structured terminal description system, with Terminfo becoming the standard in AT&T's UNIX variants while Termcap persisted in BSD-derived systems. A primary structural difference lies in storage format: Termcap entries are stored as plain text files using colon-separated fields (e.g., /etc/termcap), which are parsed at runtime, potentially leading to slower access on large databases. In contrast, Terminfo uses a compiled binary format, where source descriptions are processed by the 'tic' compiler into hashed database files (e.g., in /usr/share/terminfo), enabling faster lookups and reduced parsing overhead. Regarding hierarchy, Termcap supports a single "tc=" (terminal capability) inclusion per entry to inherit from another description, limiting reuse to linear chains. , however, allows multiple "use=" directives in its source files, which are compiled into chained references, facilitating more complex and modular hierarchies for terminal variants. Terminfo also expands on capabilities, supporting longer names (up to five characters versus Termcap's two-character codes) and more parameters per capability, accommodating approximately 600 entries in modern implementations compared to Termcap's roughly 250. This enables richer descriptions, such as advanced color support and parameterized strings, which Termcap handles less efficiently due to its fixed-format constraints. The application programming interfaces (APIs) differ significantly, with providing functions like setupterm() for initialization and del_curterm() for cleanup, integrated into curses libraries for structured access. 's API, based on functions like tgetent() and tgoto(), lacks these and requires layers for with -based systems, as the two are not directly interchangeable.

and

The from to involved a series of tools designed to facilitate the of terminal descriptions while preserving with existing software. The captoinfo , part of the package and available in many systems, translates source files into source format by parsing entries and generating equivalent compiled descriptions, addressing the limitations of 's text-based structure. Similarly, the infocmp command, with its -C option, can decompile entries into notation for reverse or verification during . Many distributions, such as those based on and , continue to ship both and databases—typically /etc/termcap alongside the compiled directories in /usr/share/terminfo—to support legacy applications without requiring immediate rewrites. To enable backward compatibility, modern implementations like the library provide emulation modes that internally query the database and translate results into the expected Termcap format, allowing older programs using functions such as tgetent or tgetstr to function seamlessly. This emulation is configurable via environment variables, including TERMINFO, which specifies the directory path for files (defaulting to /usr/share/terminfo on ), ensuring that systems can prioritize Terminfo while falling back to Termcap if needed. standards, as defined by the Open Group, endorse Terminfo as the primary interface for terminal capabilities in Issue 4 (1990) and subsequent versions, while permitting Termcap for legacy support, which has encouraged its retention in standards-compliant systems. Linux distributions adopted as the preferred format starting in the early , coinciding with the rise of and System V-derived libraries, though /etc/termcap files are still maintained for compatibility with pre- software. By the 2000s, had become the for new applications, largely supplanting Termcap in development practices. However, challenges persist in full equivalence, particularly with Termcap's padding mechanisms—delays inserted after slow terminal operations—which represents more flexibly using parameterized strings and flags (e.g., mandatory vs. advisory padding), leading to potential mismatches during conversion where Termcap's simpler delay syntax cannot be perfectly mapped. As a result, Termcap continues to linger in shell scripts, embedded systems, and unmodified legacy binaries that assume its availability.

Obsolete Aspects

Deprecated Capabilities

The hz capability in Termcap indicates that the terminal, such as the , cannot properly display the character (~), which was reserved for internal display commands and would cause screen garbling if output directly; programs were required to substitute it with alternative characters or treat it as a no-op to avoid hardware glitches. This feature addressed a specific quirk of early 1970s character-cell terminals like the , but became obsolete by the 1980s as such hardware was phased out in favor of more reliable character-cell and later raster-based displays. The OT prefix in modern implementations like denotes obsolete Termcap capabilities ported to for , often serving as placeholders for vendor-specific or legacy behaviors that were rarely utilized even in their era; these are typically ignored by parsers in contemporary systems to prevent unnecessary complexity. For instance, capabilities like OTbs () or OTrs (reset string) capture terminal-specific hacks from vendors such as or TeleVideo, but their use has been deprecated due to lack of relevance in standardized environments. Other examples include xr (no raster operations) and xx (no XON/XOFF flow control). Related to early CRT limitations, the ug capability specifies the number of "magic cookie" glitches—extra blank spaces or garbage characters—produced after underline mode changes on certain old character-cell displays, where attribute toggles shifted character positioning by one or more cells. Terminals like the TVI 912 required this padding adjustment (e.g., ug#1), but the issue stemmed from hardware constraints absent in later models. These capabilities were removed from active use because they catered to quirks of defunct character-cell CRTs, rendered unnecessary by the shift to raster displays and standardized escape sequences like ANSI, which handle attributes without positional glitches or special character restrictions. Modern libraries such as mark approximately 25 capabilities as obsolete (from BSD 4.3), often omitting or ignoring them in compiled databases to reduce size and improve performance, focusing instead on equivalents where applicable.

Legacy Hardware Support

Termcap continues to provide essential compatibility for a range of classic video display terminals from the , enabling software to interface with hardware that lacks modern features like advanced escape sequences or color support. Notable entries include the , introduced in 1974 and serving as the original terminal for the , which features a 12-inch screen with basic cursor addressing via escape codes. Similarly, the DEC VT52 from 1975 is supported through variants like vt52+arrows and xterm-vt52, offering 24x80 resolution, limited line-drawing characters, and arrow key navigation essential for early cursor-based applications. The , an electromechanical from 1963, has dedicated entries such as tty33 and tty35, describing its 72-column hardcopy output, bell signal via ASCII ^G, and handling for low-speed . In practical use cases, terminal emulators such as incorporate Termcap-derived descriptions to enable fallback modes for these legacy devices, allowing seamless operation in environments where full / emulation is unavailable or unnecessary. For instance, xterm's VT52 mode relies on Termcap capabilities to handle basic screen updates and keypad input, ensuring compatibility during initialization or when connected to serial lines. This support extends to retro computing setups and serial consoles, where enthusiasts connect vintage systems like machines or early Unix workstations to modern hosts via interfaces, using Termcap to interpret device-specific behaviors without requiring hardware modifications. Open-source initiatives, particularly the project maintained since 1996, actively preserve and update Termcap entries for rare hardware, incorporating contributions from developers to refine descriptions for terminals like the DECwriter series (e.g., dw2 for the DECwriter II) and HP models such as the 2621 and hpterm. These efforts involve testing with tools like vttest and integrating vendor-sourced data from archives, ensuring entries remain accurate for emulation and reverse-engineering projects. The terminfo database includes numerous legacy entries for 1970s-1980s hardware, supporting preservation software in museums, hobbyist restorations, and even select embedded systems that mimic old serial interfaces for compatibility in constrained environments.

References

  1. [1]
    termcap(5) - OpenBSD manual pages
    The termcap file is a database describing terminals, used, for example, by vi(1) and curses(3). Terminals are described in termcap by giving a set of ...
  2. [2]
    termcap(5)
    ### Extracted HISTORY Section
  3. [3]
    termcap(5): terminal capability database - Linux man page
    The termcap database is an obsolete facility for describing the capabilities of character-cell terminals and printers.Missing: history | Show results with:history
  4. [4]
    termcap - terminal capability data base
    Termcap is a data base describing terminals used primarily by ex (UCB) and vi (UCB), and also by tset (UCB). Terminals are described in termcap by giving a ...
  5. [5]
    The Termcap Library - GNU.org
    Termcap is a library and data base that enables programs to use display terminals in a terminal-independent manner. It originated in Berkeley Unix.
  6. [6]
    Twenty Years of Berkeley Unix : From AT&T-Owned to Freely - O'Reilly
    Along with the enhanced Pascal system, vi and termcap for several terminals was included. Once again Bill Joy single-handedly put together distributions, ...
  7. [7]
    termcap(5) - Linux manual page - man7.org
    Fields are separated by ':'. The first field of each entry starts at the left-hand margin, and contains a list of names for the terminal, separated by '|'. The ...
  8. [8]
    The Termcap Library - Definitions of the Terminal Capabilities
    This section documents the capabilities that describe the basic and nature of the terminal, and also those that are relevant to the output of graphic characters ...
  9. [9]
    tgetent
    The tgetflag() function gets the boolean entry for id. The tgetnum() function gets the numeric entry for id. The tgetstr() function gets the string entry for id ...
  10. [10]
    TCTEST – A Termcap Test Utility - invisible-island.net
    Strang states that Bill Joy wrote the first version of the termcap library ... Translating from termcap to terminfo is much simpler than translating from terminfo ...
  11. [11]
    History of the Unix Terminal: How Video Killed the Printer Star
    Feb 23, 2025 · One solution Bill Joy came up with was Termcap, a database of hardware terminals and their capabilities, such as the number of columns the ...
  12. [12]
    IBM, sonic delay lines, and the history of the 80×24 display
    Nov 7, 2019 · In 1971, IBM introduced a terminal with an 80×24 display (the 3270) and it soon became the best-selling terminal, forcing competing terminals to match its 80× ...Missing: challenges | Show results with:challenges
  13. [13]
  14. [14]
    os_msdos - Vim documentation
    Two versions for MS-DOS |msdos-versions| 2. Known problems |msdos-problems| 3. Long file names |msdos-longfname| 4. Termcap codes |msdos-termcap| 5. ... port ...
  15. [15]
    [Chapter 7] Advanced Editing
    vi gets operating instructions about your terminal type from a file called /etc/termcap. (In System V, termcap has been replaced with an alternate terminal ...
  16. [16]
    NCURSES – New Curses - invisible-island.net
    Thomas Dickey is the maintainer/developer of ncurses. This page gives some background and pointers to ncurses resources.
  17. [17]
    termcap for XTERM - invisible-island.net
    GNU termcap does not have this limit. # # I checked the limits using ncurses "captoinfo -CrTUvx", which prints # the resolved length of each entry in a ...Missing: design | Show results with:design
  18. [18]
    [PDF] UNIX PROGRAMMER'S MANUAL - Bitsavers.org
    for now you should try to limit the number of aliases you have to a reasonable number ... 10 or. 15 is reasonable .. 50 or 60 will cause a noticeable delay ...
  19. [19]
  20. [20]
    [PDF] ODYSSEY - Minnie.tuhs.org
    In the Fall of 1979, Bob Fabry responded to DARPA's interest in moving towards UNIX by writing a proposal suggesting that. Berkeley develop an enhanced version ...
  21. [21]
    termcap(5) — manpages — Debian trixie — Debian Manpages
    /etc/termcap is an ASCII file (the database master) that lists the capabilities of many different types of terminals. Programs can read termcap to find the ...Missing: flat specification
  22. [22]
    Discussion of termcap and terminfo (also the "curses" library), how ...
    The termcap and terminfo databases are UNIX's solution to the difficulty of supporting many terminals without writing special drivers for each terminal. Termcap ...<|control11|><|separator|>
  23. [23]
    cap_mkdb
    ### Summary of cap_mkdb from FreeBSD Manual Page
  24. [24]
  25. [25]
    The Termcap Library - tgoto
    `tgoto` handles cursor motion, especially for `cm'`, avoiding issues with nulls, tabs, and newlines. It takes a `cm` string and two cursor positions.Missing: example | Show results with:example
  26. [26]
    curs_termcap(3) - FreeBSD Manual Pages
    NAME PC, UP, BC, ospeed, tgetent, tgetflag, tgetnum, tgetstr, tgoto, tputs - curses emulation of termcap ... HISTORY Bill Joy originated a forerunner of termcap ...
  27. [27]
    Announcing ncurses 5.7 - invisible-island.net
    The ncurses (new curses) library is a free software emulation of curses in System V Release 4.0, and more. It uses terminfo format, supports pads and color.Release Notes · Features Of Ncurses · State Of The Package
  28. [28]
    termcap(3ncurses) — ncurses-doc — Debian testing
    Bill Joy originated a forerunner of termcap called “ttycap”, dated September 1977, and released in 1BSD (March 1978). It used many of the same function names ...Description · Applying String Capabilities · HistoryMissing: initial | Show results with:initial<|separator|>
  29. [29]
    user_caps 5 2025-08-16 ncurses 6.5 File formats - invisible-island.net
    The terminfo database uses a binary format; binary compatibility was ensured by using a header that counted the number of items in the tables for each type ...
  30. [30]
    captoinfo Command - IBM
    The captoinfo command converts a termcap source file to a terminfo source file and displays it on the screen. The termcap file format is an older format. The ...Missing: utilities infotocap
  31. [31]
    infotocap - man pages section 8: System Administration Commands
    Jul 27, 2022 · ... termcap description is written to standard output. Terminfo use capabilities are translated directly to termcap tc capabilities. -v print ...Missing: tput | Show results with:tput
  32. [32]
    Using tput - Portable Terminal Control From Scripts - GNU.org
    GNU tput by default accepts termcap name if the capability a user specifies is not a terminfo name. This option tells tput not to try terminfo names and look up ...
  33. [33]
    tput(1) - Arch manual pages
    tput uses the terminfo library and database to make terminal-specific capabilities and information available to the shell, to initialize or reset the terminal.
  34. [34]
    term - Vim documentation
    Which external termcap file is used varies from system to system and may depend on the environment variables "TERMCAP" and "TERMPATH". See "man tgetent ...
  35. [35]
    https://dept-info.labri.fr/~strandh/Teaching/PFS/C...
    ... Emacs config.h may rename various library ... termcap file. It is not a limit. Make it large ... fallback. */ if (bp) term_entry = bp; termcap_name ...
  36. [36]
    termcap(5) - NetBSD Manual Pages
    Types of Capabilities Capabilities in capfile are of three types: Boolean capabilities, numeric capabilities, and string capabilities. Boolean capabilities are ...Missing: OpenBSD | Show results with:OpenBSD
  37. [37]
    tgetent(3) - NetBSD Manual Pages
    The tgetent() function extracts the entry for terminal name into the buffer at bp. The bp argument should be a character buffer of size 1024 and must be ...
  38. [38]
    user_caps(5) - Linux manual page - man7.org
    During the 1990s, some users were reluctant to use terminfo in spite of its performance advantages over termcap: • The fixed repertoire prevented users from ...Missing: 90%
  39. [39]
    tgetent(3) - NetBSD Manual Pages
    If TERMCAP does not begin with a slash and name is different from TERM, tgetent() searches the files $HOME/.termcap and /usr/share/misc/termcap, in that ...
  40. [40]
    termcap(5) - Arch manual pages
    Termcap entries must be defined on a single logical line, with '\' used to suppress the newline. Fields are separated by ':'. The first field of each entry ...Missing: 2BSD | Show results with:2BSD
  41. [41]
    Xterm Control Sequences - XFree86
    Xterm provides control sequences and menu entries for switching between the two. Most full-screen applications use terminfo or termcap to obtain strings used to ...Missing: vs100 | Show results with:vs100
  42. [42]
    5. Termcap and Terminfo Issues
    Most Linux distributions now use terminfo, but still retain the older termcap libraries for compatibility with legacy applications (see /etc/termcap ).Missing: auto- conversion
  43. [43]
    What would cause deleting a character in busybox vi to have ...
    Nov 22, 2020 · The ex- vi could be compiled with termcap , curses or ncurses as TERMLIB , and depending on the option it would support or not an xterm terminal ...Scroll inside Screen, or Pause Output - Unix & Linux Stack ExchangeLaunch process with limited capabilities on minimal Busybox-based ...More results from unix.stackexchange.com
  44. [44]
    NCURSES — Frequently Asked Questions (FAQ) - invisible-island.net
    Mar 16, 2022 · 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.
  45. [45]
    Text-Terminal-HOWTO: Terminfo and Termcap (detailed)
    Terminfo (formerly Termcap) is a database of terminal capabilities and more. For every (well almost) model of terminal it tells application programs what the ...
  46. [46]
    terminfo(5) - Linux manual page - man7.org
    They were used in some post-4.1 versions of System V curses, e.g., Solaris 2.5 and IRIX 6.x. Except for YI, the ncurses termcap names for them are invented.
  47. [47]
    terminfo.src for NCURSES - invisible-island.net
    ... entries in a canonical form). # # The termcap version is generated automatically from the master version # using tic -C. This filtering leaves in the OT ...
  48. [48]
    captoinfo - man pages section 8: System Administration Commands
    Jul 27, 2022 · captoinfo should be used to convert termcap entries to terminfo entries because the termcap database may not be supplied in future releases.
  49. [49]
    infocmp(1M) - Arch manual pages
    infocmp can be used to compare a binary terminfo entry with other terminfo entries, rewrite a terminfo description to take advantage of the use= terminfo field, ...
  50. [50]
    Install-Notes for NCURSES - invisible-island.net
    The ncurses library includes a termcap emulation that queries the terminfo database, so even applications that use raw termcap to query terminal ...
  51. [51]
    TERMINFO environment variable (UNIX) - IBM
    TERMINFO tells DB-Access to communicate with the terminfo directory instead of the termcap file. The terminfo directory has subdirectories that contain files ...
  52. [52]
    Terminfo Source Format (ENHANCED CURSES)
    Capability names adhere to an informal length limit of five characters. Whenever possible, capability names are chosen to be the same as or similar to those ...
  53. [53]
    termcap(3) - OpenBSD manual pages
    Meanwhile, GNU termcap was under development, starting in 1990. The first release (termcap 1.0) in 1991 included a termcap.h header. The second release (termcap ...Missing: 1979 | Show results with:1979
  54. [54]
    xterm(1) - invisible-island.net
    The xterm program is a terminal emulator for the X Window System. It provides DEC VT102/VT220 and selected features from higher-level terminals.