Skip to main content

Brief History of Escape Codes

When installing Linux on a computer, I always install a program called sl. This program displays a train when you execute sl. It is not a practical program but rather a program that gives you time to think when you make a typo with the commonly used ls command in the terminal. Showing a train on the screen helps you calm down and not make other mistakes when you are in a hurry to type. That's why I install this program.


The terminal is a program that receives and displays two streams, stdout, and stderr, from a program. These outputs are sequential outputs and typically flow from the top left to the bottom right. However, to draw new characters on an already-used screen, a special method is needed. This special method is called escape codes.

Escape codes are a kind of promise defined in the terminal. Currently, these promises follow the standards defined in ISO 6429. However, in the past, there was no unified consensus, and each terminal had different rules. Understanding this may require knowledge of computer history.

Today, the term "terminal" means an application for the command-line interface(CLI). However, in the past, a terminal was literally the endpoint device of a computer. This terminal was connected to a mainframe computer and was responsible for its input/output. The reason that modern terminal apps are called "terminal emulators" is that they emulate these old-age terminal devices. Terminals were manufactured by various companies. For instance, ADM-3A, IBM's IBM 2260, and IBM 3270, and the VT series of DEC, which was later merged with HP. Each had its own standards for controlling terminals.


Escape codes were not compatible across different terminals; efforts to standardize them began in the 1970s. The first standard was ECMA-48, which was first published in 1976. However, the biggest impact on modern escape codes was the VT100, produced by DEC in 1978. The VT100 introduced the Control Sequence Introducer(CSI) and various commands, including important functions such as cursor movement and scrolling, which are still used in modern terminal emulators. Based on the implementation of the VT100, ANSI released the ANSI X3.64 standard in 1979, and in 1983, ISO published ISO 6429 based on ECMA-48 and ANSI X3.64. In 1992, some codes are added. All modern terminal emulators implement escape codes based on ISO 6429.


Popular posts from this blog

Type Conversion in Rust

Type conversion is not special in Rust. It's just a function that takes ownership of the value and returns the other type. So you can name convert functions anything. However, it's a convention to use as_ , to_ , and into_ prefixed name or to use from_ prefixed constructor. From You can create any function for type conversion. However, if you want to provide generic interfaces, you'd better implement the From trait. For instance, you should implement From<X> for Y when you want the interface that converts the X type value to the Y type value. The From trait have an associated function named from . You can call this function like From::from(x) . You also can call it like Y::from(x) if the compiler cannot infer the type of the destination type. Into From have an associated function, it makes you be able to specify the destination type. It's why From has an associated function instead of a method, but on the other hands, you cannot use it as a me

Do not use garbage collection to catch memory leak

Garbage collection is a technique that automatically releases unnecessary memory. It's very famous because many programming languages adopted garbage collection after John McCarthy implemented it in Lisp. However, there are a few people who misunderstand what garbage collection does. If you think garbage collection prevents a memory leak, unfortunately, you are one of them. Garbage collection cannot prevent a memory leak. There is no way to avoid all memory leaks if you are using Turing-complete language. To understand it you should know what a memory leak is. Wikipedia describes a memory leak as the following: a type of resource leak that occurs when a computer program incorrectly manages memory allocations in such a way that memory which is no longer needed is not released. Briefly, a memory leak is a bug that doesn't release a memory that you don't use. So it is first to find the memory which will not be used in order to detect memory leaks. Unfortunately, it i

[C++] Handling Exceptions in Constructors

When you use RAII idiom, there are often situations where constructors have to do complex tasks. These complex tasks can sometimes fail, resulting in throwing exceptions. This raises a concern: Is it okay to throw exceptions in constructors? The first concern is memory leaks. Fortunately, memory leaks do not occur. Variables created on the stack are released through stack unwinding, and if an exception occurs during heap allocation with the new operator, the new operator automatically deallocates the memory and returns nullptr . The next concern is whether the destructor of the member variables will be called correctly. However, this is also not a problem. When an exception occurs, member variables can be divided into three categories: fully initialized member variables, member variables being initialized, and uninitialized member variables. Fully initialized member variables have had their constructors called and memory allocations completed successfully. In the example code, t