ANSI escape sequences are a standard for
in-band signaling
In telecommunications, in-band signaling is the sending of control information within the same band or channel used for data such as voice or video. This is in contrast to out-of-band signaling which is sent over a different channel, or even o ...
to control cursor location, color, font styling, and other options on video
text terminal
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 ...
s and
terminal emulator
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 termin ...
s. Certain sequences of
byte
The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable unit ...
s, 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.
ANSI sequences were introduced in the 1970s to replace vendor-specific sequences and became widespread in the computer equipment market by the early 1980s. They are used in development, scientific, commercial text-based applications as well as
bulletin board system
A bulletin board system (BBS), also called computer bulletin board service (CBBS), is a computer server running software that allows users to connect to the system using a terminal program. Once logged in, the user can perform functions such as ...
s to offer standardized functionality.
Although hardware text terminals have become increasingly rare in the 21st century, the relevance of the ANSI standard persists because a great majority of terminal emulators and command consoles interpret at least a portion of the ANSI standard.
History
Almost all manufacturers of video terminals added vendor-specific escape sequences to perform operations such as placing the cursor at arbitrary positions on the screen. One example is the
VT52
The VT50 was a CRT-based computer terminal introduced by Digital Equipment Corporation (DEC) in July 1974. It provided a display with 12 rows and 80 columns of upper-case text, and used an expanded set of control characters and forward-only scro ...
terminal, which allowed the cursor to be placed at an x,y location on the screen by sending the character, a character, and then two characters representing numerical values equal to the x,y location plus 32 (thus starting at the ASCII space character and avoiding the control characters). The
Hazeltine 1500
The Hazeltine 1500 was a popular smart terminal introduced by Hazeltine Corporation in April 1977 at a price of . Using a microprocessor and semiconductor random access memory, it implemented the basic features of the earlier Hazeltine 2000 in a ...
had a similar feature, invoked using , and then the X and Y positions separated with a comma. While the two terminals had identical functionality in this regard, different control sequences had to be used to invoke them.
As these sequences were different for different terminals, elaborate libraries such as
termcap
Termcap (''terminal capability'') is a software library and database used on Unix-like computers. It enables programs to use display computer terminals in a device-independent manner, which greatly simplifies the process of writing portable text ...
("terminal capabilities") and utilities such as
tput
In computing, tput is a standard Unix operating system command which makes use of terminal capabilities.
Depending on the system, ''tput'' uses the terminfo or termcap database, as well as looking into the environment for the terminal type.
...
had to be created so programs could use the same
API
An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how ...
to work with any terminal. In addition, many of these terminals required sending numbers (such as row and column) as the binary values of the characters; for some programming languages, and for systems that did not use ASCII internally, it was often difficult to turn a number into the correct character.
The ANSI standard attempted to address these problems by making a command set that all terminals would use and requiring all numeric information to be transmitted as ASCII numbers. The first standard in the series was ECMA-48, adopted in 1976.
It was a continuation of a series of character coding standards, the first one being
ECMA-6
ISO/IEC 646 is a set of ISO/IEC standards, described as ''Information technology — ISO 7-bit coded character set for information interchange'' and developed in cooperation with ASCII at least since 1964. Since its first edition in ...
from 1965, a 7-bit standard from which
ISO 646
ISO/IEC 646 is a set of ISO/IEC standards, described as ''Information technology — ISO 7-bit coded character set for information interchange'' and developed in cooperation with ASCII at least since 1964. Since its first edition in ...
originates. The name "ANSI escape sequence" dates from 1979 when
ANSI
The American National Standards Institute (ANSI ) is a private non-profit organization that oversees the development of voluntary consensus standards for products, services, processes, systems, and personnel in the United States. The organi ...
adopted ANSI X3.64. The ANSI X3L2 committee collaborated with the
ECMA committee TC 1 to produce nearly identical standards. These two standards were merged into an international standard, ISO 6429.
In 1994, ANSI withdrew its standard in favor of the international standard.
The first popular video terminal to support these sequences was the
Digital VT100
The VT100 is a video terminal, introduced in August 1978 by Digital Equipment Corporation (DEC). It was one of the first terminals to support ANSI escape codes for cursor control and other tasks, and added a number of extended codes for special f ...
, introduced in 1978.
This model was very successful in the market, which sparked a variety of VT100 clones, among the earliest and most popular of which was the much more affordable
Zenith Z-19 in 1979. Others included the
Qume QVT-108,
Televideo
TeleVideo Corporation was a U.S. company that achieved its peak of success in the early 1980s producing computer terminals. TeleVideo was founded in 1975 by K. Philip Hwang, a Utah State University, Hanyang University graduate born in South Kore ...
TVI-970,
Wyse
WYSE (970 AM) is a radio station located in Canton, North Carolina, that simulcasts WISE's sports format from Asheville, North Carolina. Owned by the Asheville Radio Group subsidiary of Saga Communications, the station is licensed by the Fed ...
WY-99GT as well as optional "VT100" or "VT103" or "ANSI" modes with varying degrees of compatibility on many other brands. The popularity of these gradually led to more and more software (especially
bulletin board system
A bulletin board system (BBS), also called computer bulletin board service (CBBS), is a computer server running software that allows users to connect to the system using a terminal program. Once logged in, the user can perform functions such as ...
s and other
online service
An online service provider (OSP) can, for example, be an Internet service provider, an email provider, a news provider (press), an entertainment provider (music, movies), a search engine, an e-commerce site, an online banking site, a health site, ...
s) assuming the escape sequences worked, leading to almost all new terminals and emulator programs supporting them.
In 1981, ANSI X3.64 was adopted for use in the US government by
FIPS publication 86. Later, the US government stopped duplicating industry standards, so FIPS pub. 86 was withdrawn.
ECMA-48 has been updated several times and is currently at its 5th edition, from 1991. It is also adopted by
ISO
ISO is the most common abbreviation for the International Organization for Standardization.
ISO or Iso may also refer to: Business and finance
* Iso (supermarket), a chain of Danish supermarkets incorporated into the SuperBest chain in 2007
* Iso ...
and
IEC
The International Electrotechnical Commission (IEC; in French: ''Commission électrotechnique internationale'') is an international standards organization that prepares and publishes international standards for all electrical, electronic and r ...
as standard ISO/IEC 6429.
A version is adopted as a
Japanese Industrial Standard
are the standards used for industrial activities in Japan, coordinated by the Japanese Industrial Standards Committee (JISC) and published by the Japanese Standards Association (JSA). The JISC is composed of many nationwide committees and play ...
, as
JIS X 0211 JIS X 0211, originally designated JIS C 6323 is a Japanese Industrial Standard defining C0 and C1 control codes and control sequences. It was first established in 1986, with subsequent editions in 1991 and 1994.
It defines C0 and C1 control charac ...
.
Related standards include
ITU T.61
T.61 is an ITU-T Recommendation for a Teletex character set. T.61 predated Unicode,
and was the primary character set in ASN.1 used in early versions of X.500 and X.509
for encoding strings containing characters used in Western European languag ...
, the
Teletex
Teletex was ITU-T specification F.200 for a text and document communications service that could be provided over telephone lines. It was rapidly superseded by e-mail but the name ''Teletex'' lives on in several of the X.500 standard attributes u ...
standard, and the ISO/IEC 8613, the
Open Document Architecture
The Open Document Architecture (ODA) and interchange format (informally referred to as just ODA) is a free and open international standard document file format maintained by the ITU-T to replace all proprietary document file formats. ODA is deta ...
standard (mainly ISO/IEC 8613-6 or ITU T.416). The two systems share many escape codes with the ANSI system, with extensions that are not necessarily meaningful to computer terminals. Both systems quickly fell into disuse, but ECMA-48 does mark the extensions used in them as reserved.
Platform support
Unix-like systems
On these systems the terminal (or emulator) self-identifies using the
$TERM
environment variable. A database library such as
termcap
Termcap (''terminal capability'') is a software library and database used on Unix-like computers. It enables programs to use display computer terminals in a device-independent manner, which greatly simplifies the process of writing portable text ...
or
terminfo
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
* fast ...
would perform a lookup to derive the capabilities of the terminal and specific escape sequences to use the capabilities, which may deviate from ANSI in early days.
Although such libraries were primarily developed on and for Unix, by the mid-1980s programs running on
Unix-like
A Unix-like (sometimes referred to as UN*X or *nix) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-li ...
operating systems could almost always assume they were using a terminal or emulator that supported ANSI sequences; this led to widespread use of ANSI by programs running on those platforms. For instance, many games and shell scripts, and utilities such as color directory listings, directly write the ANSI sequences and thus cannot be used on a terminal that does not interpret them. Many programs, including
text editor
A text editor is a type of computer program that edits plain text. Such programs are sometimes known as "notepad" software (e.g. Windows Notepad). Text editors are provided with operating systems and software development packages, and can be us ...
s such as
vi and
GNU Emacs
GNU Emacs is a free software text editor. It was created by GNU Project founder Richard Stallman, based on the Emacs editor developed for Unix operating systems. GNU Emacs has been a central component of the GNU project and a flagship project of ...
, use termcap or terminfo, or use libraries such as
curses
A curse (also called an imprecation, malediction, execration, malison, anathema, or commination) is any expressed wish that some form of adversity or misfortune will befall or attach to one or more persons, a place, or an object. In particular ...
that use termcap or terminfo, and thus in theory support non-ANSI terminals, but this is so rarely tested nowadays that they are
unlikely to work with those terminals.
Terminal emulator
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 termin ...
s for communicating with local programs as well as remote machines and the text
system console
One meaning of system console, computer console, root console, operator's console, or simply console is the text entry and display device for system administration messages, particularly those from the BIOS or boot loader, the kernel, from the ...
almost always support ANSI escape codes. This includes terminal emulators such as
xterm
In computing, xterm is the standard terminal emulator for the X Window System. It allows users to run programs which require a command-line interface.
If no particular program is specified, xterm runs the user's shell. An X display can sho ...
,
rxvt
Rxvt (acronym for our extended virtual terminal) is a terminal emulator for the X Window System, and in the form of a Cygwin port, for Windows.
History
Rxvt was originally written by Rob Nation and later extensively modified by Mark Olesen, who ...
,
GNOME Terminal
GNOME Terminal is a terminal emulator for the GNOME desktop environment written by Havoc Pennington and others. Terminal emulators allow users to access a UNIX shell while remaining on their graphical desktop.
Features
GNOME Terminal (gnome-term ...
, and
Konsole
Konsole is a free and open-source terminal emulator graphical application which is part of KDE Applications and ships with the KDE desktop environment. Konsole was originally written by Lars Doelle. It ls licensed under the GPL-2.0-or-later and ...
on systems with
X11
The X Window System (X11, or simply X) is a windowing system for bitmap displays, common on Unix-like operating systems.
X provides the basic framework for a GUI environment: drawing and moving windows on the display device and interacting wi ...
-based or
Wayland-based window systems, and
Terminal.app and third-party terminal emulators such as
iTerm2 on
macOS
macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and lapt ...
.
CP/M
CP/M machines varied and several competing terminals existed, like for printers, each with their own control sequences. Some early systems were
headless (needing an external terminal) and personal computers with a native screen typically emulated a terminal. Application developers had to support various popular terminals and to provide an installation program to configure them. Despite the CP/M hardware abstraction layer (
BIOS
In computing, BIOS (, ; Basic Input/Output System, also known as the System BIOS, ROM BIOS, BIOS ROM or PC BIOS) is firmware used to provide runtime services for operating systems and programs and to perform hardware initialization during the ...
), even for the same microprocessor, vendors provided platform-specific versions due to the competing disk formats, that would also be preconfigured for the native terminal (for example, various machine-specific
WordStar
WordStar is a word processor application for microcomputers. It was published by MicroPro International and originally written for the CP/M-80 operating system, and later written also for MS-DOS and other 16-bit PC OSes. Rob Barnaby was the so ...
adaptations were released).
The headless
Altair 8800 was typically connected to a
teletype
A teleprinter (teletypewriter, teletype or TTY) is an electromechanical device that can be used to send and receive typed messages through various communications channels, in both point-to-point and point-to-multipoint configurations. Init ...
such as the
Model 33 ASR or to an external terminal like the
TeleVideo 920C, needing to output their respective sequences. The
Osborne 1
The Osborne 1 is the first commercially successful portable computer, released on April 3, 1981 by Osborne Computer Corporation. It weighs , cost US$1,795, and runs the CP/M 2.2 operating system. It is powered from a wall socket, as it has no ...
and
Kaypro II
Kaypro Corporation was an American home and personal computer manufacturer based out of San Diego in the 1980s. The company was founded by Non-Linear Systems (NLS) to compete with the popular Osborne 1 portable microcomputer. Kaypro produced a ...
computers natively emulated a subset of the TeleVideo 920C and
ADM-3A
The ADM-3A was an influential early video display terminal, introduced in 1976. It was manufactured by Lear Siegler and had a 12-inch screen displaying 12 or 24 lines of 80 characters. It set a new industry low single unit price of $995. Its " ...
control codes, respectively. The
TRS-80 Model 4
The TRS-80 Model 4 is the last Z80-based home computer family by Radio Shack
RadioShack, formerly RadioShack Corporation, is an American retailer founded in 1921.
At its peak in 1999, RadioShack operated over 8,000 worldwide stores named Rad ...
and the
Xerox 820
The Xerox 820 Information Processor is an 8-bit desktop computer sold by Xerox in the early 1980s. The computer runs under the CP/M operating system and uses floppy disk drives for mass storage. The microprocessor board is a licensed variant of ...
also emulated the Lear Siegler ADM-3A. The
Zenith Z-89
The Z-89 is a personal computer produced by Zenith Data Systems (ZDS) in the early 1980s.
Description
The Zenith Z-89 is based on the Zilog Z80 microprocessor running at 2.048 MHz, and supports the HDOS and CP/M operating systems. The ...
,
Heathkit H8
Heathkit's H8 is an Intel 8080A-based microcomputer sold in kit form starting in 1977. The H8 is similar to the S-100 bus computers of the era, and like those machines is often used with the CP/M operating system on floppy disk.
The main diffe ...
and
Amstrad PCW CP/M-80 computers implemented the Zenith Z19 (Heathkit H19) terminal codes, mostly compatible with
VT52
The VT50 was a CRT-based computer terminal introduced by Digital Equipment Corporation (DEC) in July 1974. It provided a display with 12 rows and 80 columns of upper-case text, and used an expanded set of control characters and forward-only scro ...
, the Z-89 manual also describes it as supporting ANSI.
The Microsoft
Z-80 SoftCard
The Z-80 SoftCard is a plug-in Apple II processor card developed by Microsoft to turn the computer into a CP/M system based upon the Zilog Z80 central processing unit (CPU). Becoming the most popular CP/M platform and Microsoft's top revenue sou ...
for the
Apple II
The Apple II (stylized as ) is an 8-bit home computer and one of the world's first highly successful mass-produced microcomputer products. It was designed primarily by Steve Wozniak; Jerry Manock developed the design of Apple II's foam-m ...
emulated a limited subset of the
Videx Videoterm, corresponding to the
Datamedia 1520 sequences that the UCSD-based
Apple Pascal
Apple Pascal is an implementation of Pascal for the Apple II and Apple III computer series. It is based on UCSD Pascal.
Just like other UCSD Pascal implementations, it ran on its own operating system (''Apple Pascal Operating System'', a derivati ...
supported. Its CP/M had the CONFIGIO command to adapt external terminals or run local applications that issued other control codes. Supported external terminals were the
Soroc IQ 120/140 and
Hazeltine 1500/1510.
DOS, OS/2, and Windows
MS-DOS 1.x did not support the ANSI or any other escape sequences. Only a few
control character
In computing and telecommunication, a control character or non-printing character (NPC) is a code point (a number) in a character set, that does not represent a written symbol. They are used as in-band signaling to cause effects other than the ...
s (
BEL,
CR,
LF,
BS) were interpreted by the underlying BIOS, making it almost impossible to do any kind of full-screen application. Any display effects had to be done with BIOS calls, which were notoriously slow, or by directly manipulating the IBM PC hardware.
DOS 2.0 introduced the ability to add a
device driver
In computing, a device driver is a computer program that operates or controls a particular type of device that is attached to a computer or automaton. A driver provides a software interface to hardware devices, enabling operating systems and ot ...
for the ANSI escape sequences – the ''
de facto
''De facto'' ( ; , "in fact") describes practices that exist in reality, whether or not they are officially recognized by laws or other formal norms. It is commonly used to refer to what happens in practice, in contrast with ''de jure'' ("by la ...
'' standard being , but others like ,
and are used as well (these are considerably faster as they bypass the BIOS). Slowness and the fact that it was not installed by default made software rarely take advantage of it; instead, applications continued to directly manipulate the hardware to get the text display needed. ANSI.SYS and similar drivers continued to work in
Windows 9x
Windows 9x is a generic term referring to a series of Microsoft Windows computer operating systems produced from 1995 to 2000, which were based on the Windows 95 kernel and its underlying foundation of MS-DOS, both of which were updated in su ...
up to
Windows Me
Windows Millennium Edition, or Windows Me (marketed with the pronunciation of the pronoun "me"), is an operating system developed by Microsoft as part of its Windows 9x family of Microsoft Windows operating systems. It is the successor to Windo ...
, and in NT-derived systems for 16-bit legacy programs executing under the
NTVDM
Virtual DOS machines (VDM) refer to a technology that allows running 16-bit/32-bit DOS and 16-bit Windows programs when there is already another operating system running and controlling the hardware.
Overview
Virtual DOS machines can operate eit ...
.
Many clones of DOS were able to interpret the sequences and do not require a separate ANSI driver to be loaded.
PTS-DOS
PTS-DOS (aka PTS/DOS) is a disk operating system, a DOS clone, developed in Russia by PhysTechSoft and Paragon Technology Systems.
History and versions
PhysTechSoft was formed in 1991 in Moscow, Russia by graduates and members of MIPT, inf ...
as well as
Concurrent DOS,
Multiuser DOS
Multiuser DOS is a real-time multi-user multi-tasking operating system for IBM PC-compatible microcomputers.
An evolution of the older Concurrent CP/M-86, Concurrent DOS and Concurrent DOS 386 operating systems, it was originally developed by ...
and
REAL/32
Multiuser DOS is a real-time multi-user multi-tasking operating system for IBM PC-compatible microcomputers.
An evolution of the older Concurrent CP/M-86, Concurrent DOS and Concurrent DOS 386 operating systems, it was originally developed by ...
have built-in support (plus a number of extensions).
OS/2
OS/2 (Operating System/2) is a series of computer operating systems, initially created by Microsoft and IBM under the leadership of IBM software designer Ed Iacobucci. As a result of a feud between the two companies over how to position OS/2 ...
had an command that enabled the sequences.
The
Windows Console
Windows Console is the infrastructure for console applications in Microsoft Windows. An instance of a Windows Console has a screen buffer and an input buffer. It allows console apps to run inside a window or in hardware text mode (so as to oc ...
did not support ANSI escape sequences, nor did Microsoft provide any method to enable them. Some replacements or additions for the console window such as JP Software's
TCC
TCC may refer to:
Companies
*Taiwan Cement Corporation
* The Casual Courier
* The Clearing Corporation
* Trammell Crow Company
* Travancore Cochin Chemicals, Kochi, Kerala, India
* The Coring Company, Mo i Rana, Norway
Organizations
* Tanana C ...
(formerly 4NT), Michael J. Mefford's ANSI.COM, Jason Hood's
and Maximus5's
ConEmu interpreted ANSI escape sequences printed by programs. A Python package named colorama internally interpretes ANSI escape sequences in text being printed, translating them to win32 calls to modify the state of the terminal, to make it easier to port Python code using ANSI to Windows.
Cygwin performs similar translation to all output written to the console using Cygwin file descriptors, the filtering is done by the output functions of , to allow porting of POSIX C code to Windows.
In 2016, Microsoft released the
Windows 10
Windows 10 is a major release of Microsoft's Windows NT operating system. It is the direct successor to Windows 8.1, which was released nearly two years earlier. It was released to manufacturing on July 15, 2015, and later to retail on J ...
version 1511 update which unexpectedly implemented support for ANSI escape sequences, over two decades after the debut of Windows NT. This was done alongside
Windows Subsystem for Linux
Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for ser ...
, allowing
Unix-like
A Unix-like (sometimes referred to as UN*X or *nix) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-li ...
terminal-based software to use the sequences in Windows Console. This defaults to off, but Windows PowerShell 5.1 enabled it. PowerShell 6 made it possible to embed the necessary ESC character into a string with .
Windows Terminal
Windows Terminal is a multi-tabbed terminal emulator that Microsoft has developed for Windows 10 and later as a replacement for Windows Console. It can run any command-line app in a separate tab. It is preconfigured to run Command Prompt, Pow ...
, introduced in 2019, supports the sequences by default, and Microsoft intends to replace the Windows Console with Windows Terminal.
Atari ST/TT/Falcon series
Atari TOS
TOS (The Operating System) is the operating system of the Atari ST range of computers. This range includes the 520ST and 1040ST, their STF/M/FM and STE variants and the Mega ST/STE. Later, 32-bit machines ( TT, Falcon030) were developed using a ...
used the command system adapted from the
VT52
The VT50 was a CRT-based computer terminal introduced by Digital Equipment Corporation (DEC) in July 1974. It provided a display with 12 rows and 80 columns of upper-case text, and used an expanded set of control characters and forward-only scro ...
with some expansions for color support, rather than supporting ANSI escape codes.
AmigaOS
AmigaOS
AmigaOS is a family of proprietary native operating systems of the Amiga and AmigaOne personal computers. It was developed first by Commodore International and introduced with the launch of the first Amiga, the Amiga 1000, in 1985. Early versions ...
not only interprets ANSI code sequences for text output to the screen, the AmigaOS
printer
Printer may refer to:
Technology
* Printer (publishing), a person or a company
* Printer (computing), a hardware device
* Optical printer for motion picture films
People
* Nariman Printer (fl. c. 1940), Indian journalist and activist
* James ...
driver also interprets them (with extensions proprietary to AmigaOS) and translates them into the codes required for the particular printer that is actually attached.
VMS / OpenVMS
VMS was designed to be controlled using Digital's text-based video terminals such as the aforementioned
VT100
The VT100 is a video terminal, introduced in August 1978 by Digital Equipment Corporation (DEC). It was one of the first terminals to support ANSI escape codes for cursor control and other tasks, and added a number of extended codes for special f ...
; thus software tends to write the ANSI escape sequences directly (and will not work on non-ANSI terminals).
Description
C0 control codes
Almost all users assume some functions of some single-byte characters. Initially defined as part of ASCII, the default C0 control code set is now defined in ISO 6429 (ECMA-48), making it part of the same standard as the C1 set invoked by the ANSI escape sequences (although
ISO 2022
ISO/IEC 2022 ''Information technology—Character code structure and extension techniques'', is an ISO/ IEC standard (equivalent to the ECMA standard ECMA-35, the ANSI standard ANSI X3.41 and the Japanese Industrial Standard JIS X 0202) in the ...
allows the ISO 6429 C0 set to be used without the ISO 6429 C1 set, and ''vice versa'', provided that 0x1B is always ESC). This is used to shorten the amount of data transmitted, or to perform some functions that are unavailable from escape sequences:
Escape sequences vary in length. The general format for an ANSI-compliant escape sequence is defined by
ANSI X3.41 (equivalent to ECMA-35 or ISO/IEC 2022).
The escape sequences consist only of bytes in the range (all the non-control ASCII characters), and can be parsed without looking ahead. The behavior when a control character, a byte with the high bit set, or a byte that is not part of any valid sequence, is encountered before the end is undefined.
Fe Escape sequences
If the
is followed by a byte in the range 0x40 to 0x5F, the escape sequence is of type . Its interpretation is delegated to the applicable
C1 control code standard.
Accordingly, all escape sequences corresponding to C1 control codes from ANSI X3.64 / ECMA-48 follow this format.
The standard says that, in 8-bit environments, the control functions corresponding to type escape sequences (those from the set of
C1 control codes
The C0 and C1 control code or control character sets define control codes for use in text by computer systems that use ASCII and derivatives of ASCII. The codes represent additional information about the text, such as the position of a cursor, ...
) can be represented as single bytes in the 0x80–0x9F range.
This is possible in character encodings conforming to the provisions for an 8-bit code made in ISO 2022, such as the
ISO 8859
ISO/IEC 8859 is a joint ISO and IEC series of standards for 8-bit character encodings. The series of standards consists of numbered parts, such as ISO/IEC 8859-1, ISO/IEC 8859-2, etc. There are 15 parts, excluding the abandoned ISO/IEC 8859-12. ...
series. However, in character encodings used on modern devices such as
UTF-8
UTF-8 is a variable-width encoding, variable-length character encoding used for electronic communication. Defined by the Unicode Standard, the name is derived from ''Unicode'' (or ''Universal Coded Character Set'') ''Transformation Format 8-bit'' ...
or
CP-1252, those codes are often used for other purposes, so only the 2-byte sequence is typically used. In the case of UTF-8, representing a C1 control code via the
C1 Controls and Latin-1 Supplement
The Latin-1 Supplement (also called C1 Controls and Latin-1 Supplement) is the second Unicode block in the Unicode standard. It encodes the upper range of ISO 8859-1: 80 (U+0080) - FF (U+00FF). C1 Controls (0080–009F) are not graphic. Thi ...
block results in a different two-byte code (e.g. for ), but no space is saved this way.
CSI (Control Sequence Introducer) sequences
For Control Sequence Introducer, or CSI, commands, the is followed by any number (including none) of "parameter bytes" in the range 0x30–0x3F (ASCII
0–9:;<=>?
), then by any number of "intermediate bytes" in the range 0x20–0x2F (ASCII space and ), then finally by a single "final byte" in the range 0x40–0x7E (ASCII
@A–Z _`a–z~
).
All common sequences just use the parameters as a series of semicolon-separated numbers such as . Missing numbers are treated as ( acts like the middle number is , and no parameters at all in acts like a reset code). Some sequences (such as CUU) treat as in order to make missing parameters useful.
A subset of arrangements was declared "private" so that terminal manufacturers could insert their own sequences without conflicting with the standard. Sequences containing the parameter bytes
<=>?
or the final bytes 0x70–0x7E (
p–z~
) are private.
The behavior of the terminal is undefined in the case where a CSI sequence contains any character outside of the range 0x20–0x7E. These illegal characters are either C0 control characters (the range 0–0x1F), DEL (0x7F), or bytes with the high bit set. Possible responses are to ignore the byte, to process it immediately, and furthermore whether to continue with the CSI sequence, to abort it immediately, or to ignore the rest of it.
SGR (Select Graphic Rendition) parameters
The control sequence
CSI m
, named Select Graphic Rendition (SGR), sets display attributes. Several attributes can be set in the same sequence, separated by semicolons.
Each display attribute remains in effect until a following occurrence of SGR resets it.
If no codes are given, is treated as (reset / normal).
Colors
= 3-bit and 4-bit
=
The original specification only had 8 colors, and just gave them names. The SGR parameters 30–37 selected the foreground color, while 40–47 selected the background. Quite a few terminals implemented "bold" (SGR code 1) as a brighter color rather than a different font, thus providing 8 additional foreground colors. Usually you could not get these as background colors, though sometimes inverse video (SGR code 7) would allow that. Examples: to get black letters on white background use , to get red use , to get bright red use . To reset colors to their defaults, use (not supported on some terminals), or reset all attributes with . Later terminals added the ability to directly specify the "bright" colors with 90–97 and 100–107.
When hardware started using 8-bit
digital-to-analog converter
In electronics, a digital-to-analog converter (DAC, D/A, D2A, or D-to-A) is a system that converts a digital signal into an analog signal. An analog-to-digital converter (ADC) performs the reverse function.
There are several DAC archit ...
s (DACs) several pieces of software assigned 24-bit color numbers to these names. The chart below shows the default values sent to the DAC for some common hardware and software; in most cases they are configurable.
= 8-bit
=
As
256-color lookup tables became common on graphic cards, escape sequences were added to select from a pre-defined set of 256 colors:
ESC[38;5;m Select foreground color where n is a number from the table below
ESC[48;5;m Select background color
0- 7: standard colors (as in ESC [ 30–37 m)
8- 15: high intensity colors (as in ESC [ 90–97 m)
16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
232-255: grayscale from dark to light in 24 steps
The ITU's T.416 Information technology - Open Document Architecture (ODA) and interchange format: Character content architectures
uses ':' as separator characters instead:
ESC[38:5:m Select foreground color where n is a number from the table below
ESC
8:5:m Select background color
There has also been a similar but incompatible 88-color encoding using the same escape sequence, seen in and . Not much is known about the scheme besides the color codes. It uses a 4×4×4 color cube.
= 24-bit
=
As "true color" graphic cards with 16 to 24 bits of color became common, applications began to support 24-bit colors. Terminal emulators supporting setting 24-bit foreground and background colors with escape sequences include Xterm, KDE's Konsole
Konsole is a free and open-source terminal emulator graphical application which is part of KDE Applications and ships with the KDE desktop environment. Konsole was originally written by Lars Doelle. It ls licensed under the GPL-2.0-or-later and ...
, and iTerm, as well as all libvte based terminals, including GNOME Terminal
GNOME Terminal is a terminal emulator for the GNOME desktop environment written by Havoc Pennington and others. Terminal emulators allow users to access a UNIX shell while remaining on their graphical desktop.
Features
GNOME Terminal (gnome-term ...
.
ESC 38;2;;;_m_Select_RGB_foreground_color
_ESC[_48;2;;;_m_Select_RGB_background_color
The_syntax_is_likely_based_on_the_ITU's_T.416_
Open_Document_Architecture_
The_Open_Document_Architecture_(ODA)_and_interchange_format_(informally_referred_to_as_just_ODA)_is_a__free_and_open_international_standard_document_file_format_maintained_by_the_ITU-T_to_replace_all_proprietary_document_file_formats._ODA_is_deta_...
_which_was_adopted_as_ISO/IEC_8613-6_but_ended_up_as_a_commercial_failure._The_ODA_version_is_more_elaborate_and_thus_incompatible:
*_The_parameters_after_the_'2'_(r,_g,_and_b)_are_optional_and_can_be_left_empty.
*_Semicolons_are_replaced_by_colons,_as_above._
*_There_is_a_leading_"colorspace_ID".
_The_definition_of_the_colorspace_ID_is_not_included_in_that_document_so_it_may_be_blank_to_represent_the_unspecified_default.
*_In_addition_to_the_'2'_value_after_48_to_specify_a_Red-Green-Blue_format_(and_the_'5'_above_for_a_0-255_indexed_color),_there_are_alternatives_of_'0'_for_implementation-defined_and_'1'_for_transparent_-_neither_of_which_have_any_further_parameters;_'3'_specifies_colors_using_a_Cyan-Magenta-Yellow_scheme,_and_'4'_for_a_Cyan-Magenta-Yellow-Black_one,_the_latter_using_the_position_marked_as_"unused"_for_the_Black_component:
_ESC[_38:2:::::::_m_Select_RGB_foreground_color
_ESC[_48:2:::::::_m_Select_RGB_background_color
The_ITU-RGB_variation_is_supported_by_xterm,_with_the_colorspace_ID_and_tolerance_parameters_ignored._The_simpler_scheme_using_semicolons_is_initially_found_in_Konsole.
=
Before_termcap_and_terminfo_could_indicate_support_for_colors,_the_S-Lang_library_used__to_indicate_whether_a_terminal_emulator_could_use_colors_at_all_(later_reinterpreted_as_256-colors)
_and_whether_it_supports_24-bit_color.