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.

source: https://github.com/mtoyoda/sl

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.

source: https://en.wikipedia.org/wiki/IBM_2260

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.

Comments

Popular posts from this blog

[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

Iterator Adapters in Rust

An Iterator that takes another iterator and returns a new one is called an iterator adapter . The name "adapter" comes from one of the GoF's design patterns, the adapter pattern . However, in reality, it corresponds more to the decorator pattern , so if you pay too much attention to the name, you might get confused about its purpose. So it's better not to worry too much about the name. Enough complaining about the name, what does an iterator adapter do? An iterator adapter adds a task to be performed when the iterator iterates. This will be easier to understand when you see an example. The map function is one of the famous adapters. The iterator returned by the map function for those who have used functional languages iterates over new values transformed from the original values. Besides, various adapters are already implemented in the standard library. Among them, the most frequently used are those that are convenient to use with loops. Examples include the

Clear Screen with CSI Sequence

Today, following my previous post , I will explain how to clear the screen using CSI Sequences. There are two sequences in the CSI Sequence for clearing. The first one is the Erase in Line sequence, called EL . It is composed of CSI # K ; it is used to erase lines, as the name suggests. If the # is not provided, the default value is 0, and if a value is provided, it must be one of the three: 0, 1, or 2. The terminal will ignore the sequence if any other value is provided. For example, if you print 0x311b5b334b32 (or 1^[3K2 ), the terminal ignores ^[3K , and the screen displays only 12 . The behavior of 0, 1, and 2 can be summarized as follows. 0 Erases from the cursor to the end of the line. 1 Erases from the beginning of the line to the cursor. 2 Erases the entire line, regardless of the cursor's position. Remember that the EL sequence does not move the cursor's position. Therefore, if you want to erase the current line and write a new line on the c