Your terminal obeys hidden text codes that can recolor the screen and move the cursor

Your terminal obeys hidden text codes that can recolor the screen and move the cursor
Image: Intellect (generated)

In short: Inside ordinary text, a special sequence of characters can tell a terminal to change colors or move the cursor. These ANSI escape codes, standardised in the 1970s, are why colored command-line output and full-screen text programs work at all. The text you see is not always the text the machine receives.

ANSI escape sequences let control instructions travel inside the same stream of characters as ordinary text. Most begin with an escape character followed by a bracket. A terminal reads them as commands instead of printing them, which lets a program change text color, apply styling and place the cursor anywhere on the screen. The problem they addressed was fragmentation. Early video terminals from almost every manufacturer used their own escape sequences for jobs such as positioning the cursor, so software had to be written for each model.

Libraries such as termcap and utilities such as tput were built so one program could work with many terminals, but a shared command set was a cleaner answer. The first standard in the series, ECMA-48, was adopted in 1976. It required that numeric information be sent as ASCII digits, which also made programming easier on systems that did not use ASCII internally. Later, a version adopted by the American body was given the ANSI label in 1979, and the two bodies produced nearly identical standards that were eventually merged into the international standard ISO 6429.

The standard spread through the Digital VT100, introduced in 1978, and its many clones. As bulletin board systems and other online services came to assume these sequences worked, almost all later terminals and emulators added support. Adoption on personal computers was uneven. The IBM PC of 1981 did not interpret these sequences, and the ANSI.SYS driver for DOS was not installed by default. The Windows console long lacked support, and Microsoft added it in the Windows 10 version 1511 update in 2016.

Today the sequences remain relevant because most terminal emulators still interpret at least part of the standard, even though hardware text terminals have become rare. Many everyday tools rely on them for colored output, and the ability to position text anywhere on the screen is what makes full-screen terminal programs possible.

Opens the Intellect+ feed with this card first. Swipe up for the next one.

Sources

To cite this card, link to https://intellectplus.co.uk/app/technology-ansi-escape-code.

How we source, check and correct cards: Editorial standards.

General information, not professional advice. Spotted an error? Flag the card or see corrections and complaints.

Intellect Plus is a visual educational discovery platform for exploring fascinating facts and ideas. Brain Food, Not Brain Rot. What is Intellect Plus?

Related

Finding something worth knowing…