This topic was published by DevynCJohnson and viewed 2012 times since "". The last page revision was "".
- Topics - 443
ANSI codes are embedded byte commands that are read by command-lines to output the text with special formatting or perform some task on the terminal output. The ANSI codes (or escape sequences) may appear as character codes rather than formatting codes. Terminals and terminal-emulators (such as Xterm) support many ANSI codes as well as some vendor-specific codes. Learning about ANSI may help terminal users to understand how it all works and allow developers to make better programs.
Control Characters (C0 and C1 Control Codes) are not the same as ANSI codes. Control characters are the commonly used CTRL+button combinations used in a terminal such as [kbd]CTRL[/kbd]+[kbd]C[/kbd], [kbd]CTRL[/kbd]+[kbd]Z[/kbd], [kbd]CTRL[/kbd]+[kbd]D[/kbd], etc. In terminals, control characters may appear as "^C" (for "CTRL+C") in the terminal output. For instance, in a terminal, press [kbd]CTRL[/kbd]+C and then users will see "^C" in the terminal. The [kbd]CTRL[/kbd] button provides a way to input the ESC character.
NOTE: The "ESC character" is not the same as the " [kbd]ESC[/kbd] key".
ANSI codes begin with the ESC character which appears as a carat (^) in terminals. The ESC character is then followed by ASCII characters which specifically tell the terminal what to do or how to display text. The ASCII character after the ESC character may be in the ASCII range "@" to "_" (64-95 ASCII decimal). However, more possibilities are available when using the two-character escape such as the carat and bracket (^[) which is known as the Control Sequence Introducer (CSI). CSI codes use "@" to "~" (64-126 ASCII decimal) after the escape. In ASCII hexadecimal, the ESC character is 0x1B or 33 in octal.
NOTE: The carat character is not the ESC character. Terminals use the carat symbol to display or represent the ESC character.
In a terminal, to type the CSI, type "\e[". The "\e" acts as the ESC character and the "[" is the rest of the CSI. After typing the CSI, type the ASCII sequence needed to generate the desired output. For instance, in Xterm, typing "echo -e \\e[S" will scroll the screen/output up one line. To scroll up more lines, place a number before the "S" which will act as a parameter -
echo -e \\e[5S.
Attachments:You must be logged in to view attached files.