POSIX terminal interface

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.

[1][2] These include: Unlike its mainframe and minicomputer[citation needed] contemporaries, the original Unix system was developed solely for dumb terminals, and that remains the case today.

By contrast mainframes and minicomputers in closed architectures commonly use Block-oriented terminals.

Application programs use the terminal capabilities to provide textual user interfaces with windows, dialogue boxes, buttons, labels, input fields, menus, and so forth.

[10][11] The particular set of capabilities for the terminal that a (terminal-aware) program's input and output uses is obtained from the database rather than hardwired into programs and libraries, and is controlled by the TERM environment variable (and, optionally for the termcap and terminfo libraries, the TERMCAP and TERMINFO environment variables, respectively).

[16][17] In Seventh Edition Unix, BSD systems and derivatives including macOS, and Linux, each terminal device can be switched amongst multiple line disciplines.

The @ key sent from the terminal to the system would erase ("kill") the entire current contents of the editing buffer, and would be normally displayed as an '@' symbol followed by a newline sequence to move the print position to a fresh blank line.

[20][21][22][23][18] From a programming point of view, a terminal device had transmit and receive baud rates, "erase" and "kill" characters (that performed line editing, as explained), "interrupt" and "quit" characters (generating signals to all of the processes for which the terminal was a controlling terminal), "start" and "stop" characters (used for modem flow control), an "end of file" character (acting like a carriage return except discarded from the buffer by the read() system call and therefore potentially causing a zero-length result to be returned) and various basic mode flags determining whether local echo was emulated by the kernel's terminal driver, whether modem flow control was enabled, the lengths of various output delays, mapping for the carriage return character, and the three input modes.

[26][27] The programmatic interface for querying and modifying all of these modes and control characters was the ioctl() system call.

(This replaced the stty() and gtty() system calls of Sixth Edition Unix.

)[29][30] Although the "erase" and "kill" characters were modifiable from their defaults of # and @, for many years they were the pre-set defaults in the terminal device drivers, and on many Unix systems, which only altered terminal device settings as part of the login process, in system login scripts that ran after the user had entered username and password, any mistakes at the login and password prompts had to be corrected using the historical editing key characters inherited from teletypewriter terminals.

[18] These extensions comprised additional (again programmatically modifiable) special characters: The programmatic interface for querying and modifying all of these extra modes and control characters was still the ioctl() system call, which its creators (Leffler et al. 1989, p. 262) described as a "rather cluttered interface".

[32] For example, it replaced the "cooked", "cbreak", and "raw" modes of Seventh Edition with different abstractions.

Portable source code had to contain a significant amount of conditional compilation to accommodate the differences across software platforms, even though they were all notionally Unix.

[33][34] POSIX also introduced support for job control, with the termios structure containing suspend and delayed-suspend characters in addition to the control characters supported by System III and System V. It did not add any of the cooked-mode extensions from BSD, although SunOS 4.x, System V Release 4, Solaris, HP-UX, AIX, newer BSDs, macOS, and Linux have implemented them as extensions to termios.

[34] Indeed, implementations have to add non-standard fields for recording input and output baud rates.

)[40] The structure's fields are (in summary, for details see the main article[clarification needed]): The library functions are (in summary, for details see the main article[clarification needed]): The c_cc[] array member of the termios data structure specifies all of the (programmatically modifiable) special characters.

The indexes into the array are symbolic constants, one for each special character type, as in the table at right.