CSI Codes
The general structure of most ANSI escape sequences is CSI n1 ; n2... letter
. The final byte, modified by private mode characters and trailing intermediate characters, specifies the command. The numbers are optional parameters. The default value used for omitted parameters varies with the command, but is usually 1 or 0. If trailing parameters are omitted, the trailing semicolons may also be omitted.
The final byte is technically any character in the range 64 to 126 (hex 0x40 to 0x7e, ASCII @ to ~), and may be modified with leading intermediate bytes in the range 32 to 47 (hex 0x20 to 0x2f).
The colon (0x3a) is the only character not a part of the general sequence; it was left for future standardization, so any sequence containing it should be ignored. Although multiple private mode characters or trailing intermediates are permitted, there are no such known usages.
If there are any leading private mode characters, the main body of the sequence could theoretically contain any order of characters 0x30 – 0x3f instead of a well-formed semicolon-separated list of numbers, but all known terminals are nice and just use them as a flag. Sequences are also private if the final byte is in the range 112 to 126 (hex 0x70 to 0x7e, ASCII p to ~).
Examples of private escape codes include the DECTCEM (DEC text cursor enable mode) shown below. It was first introduced for the VT-300 series of video terminals.
The existence of a C0 control, DEL (0x7f), or a high characters is undefined. Typically, implementations will either cancel the sequence or execute the control and then continue parsing the CSI sequence.
Code | Name | Effect |
---|---|---|
CSI n A | CUU – Cursor Up | Moves the cursor n (default 1) cells in the given direction. If the cursor is already at the edge of the screen, this has no effect. |
CSI n B | CUD – Cursor Down | |
CSI n C | CUF – Cursor Forward | |
CSI n D | CUB – Cursor Back | |
CSI n E | CNL – Cursor Next Line | Moves cursor to beginning of the line n (default 1) lines down. |
CSI n F | CPL – Cursor Previous Line | Moves cursor to beginning of the line n (default 1) lines up. |
CSI n G | CHA – Cursor Horizontal Absolute | Moves the cursor to column n. |
CSI n ; m H | CUP – Cursor Position | Moves the cursor to row n, column m. The values are 1-based, and default to 1 (top left corner) if omitted. A sequence such as CSI ;5H is a synonym for CSI 1;5H as well as CSI 17;H is the same as CSI 17H and CSI 17;1H |
CSI n J | ED – Erase Data | Clears part of the screen. If n is zero (or missing), clear from cursor to end of screen. If n is one, clear from cursor to beginning of the screen. If n is two, clear entire screen (and moves cursor to upper left on MS-DOS ANSI.SYS). |
CSI n K | EL – Erase in Line | Erases part of the line. If n is zero (or missing), clear from cursor to the end of the line. If n is one, clear from cursor to beginning of the line. If n is two, clear entire line. Cursor position does not change. |
CSI n S | SU – Scroll Up | Scroll whole page up by n (default 1) lines. New lines are added at the bottom. (not ANSI.SYS) |
CSI n T | SD – Scroll Down | Scroll whole page down by n (default 1) lines. New lines are added at the top. (not ANSI.SYS) |
CSI n ; m f | HVP – Horizontal and Vertical Position | Moves the cursor to row n, column m. Both default to 1 if omitted. Same as CUP |
CSI n m | SGR – Select Graphic Rendition | Sets SGR parameters, including text color. After CSI can be zero or more parameters separated with ;. With no parameters, CSI m is treated as CSI 0 m (reset / normal), which is typical of most of the ANSI escape sequences. |
CSI 6 n | DSR – Device Status Report | Reports the cursor position to the application as (as though typed at the keyboard) ESC[n;mR, where n is the row and m is the column. (May not work on MS-DOS.) |
CSI s | SCP – Save Cursor Position | Saves the cursor position. |
CSI u | RCP – Restore Cursor Position | Restores the cursor position. |
CSI ?25l | DECTCEM | Hides the cursor. (Note: the trailing character is lowercase L.) |
CSI ?25h | DECTCEM | Shows the cursor. |
Code | Effect | Note |
---|---|---|
0 | Reset / Normal | all attributes off |
1 | Bright (increased intensity) or Bold | |
2 | Faint (decreased intensity) | not widely supported |
3 | Italic: on | not widely supported. Sometimes treated as inverse. |
4 | Underline: Single | |
5 | Blink: Slow | less than 150 per minute |
6 | Blink: Rapid | MS-DOS ANSI.SYS; 150 per minute or more; not widely supported |
7 | Image: Negative | inverse or reverse; swap foreground and background (reverse video) |
8 | Conceal | not widely supported |
9 | Crossed-out | Characters legible, but marked for deletion. Not widely supported. |
10 | Primary(default) font | |
11–19 | n-th alternate font | Select the n-th alternate font. 14 being the fourth alternate font, up to 19 being the 9th alternate font. |
20 | Fraktur | hardly ever supported |
21 | Bright/Bold: off or Underline: Double | bold off not widely supported, double underline hardly ever |
22 | Normal color or intensity | neither bright, bold nor faint |
23 | Not italic, not Fraktur | |
24 | Underline: None | not singly or doubly underlined |
25 | Blink: off | |
26 | Reserved | |
27 | Image: Positive | |
28 | Reveal | conceal off |
29 | Not crossed out | |
30–37 | Set text color | 30 + x, where x is from the color table below |
38 | Set xterm-256 text color | next arguments are 5;x where x is color index (0..255) |
39 | Default text color | implementation defined (according to standard) |
40–47 | Set background color | 40 + x, where x is from the color table below |
48 | Set xterm-256 background color | next arguments are 5;x where x is color index (0..255) |
49 | Default background color | implementation defined (according to standard) |
50 | Reserved | |
51 | Framed | |
52 | Encircled | |
53 | Overlined | |
54 | Not framed or encircled | |
55 | Not overlined | |
56–59 | Reserved | |
60 | ideogram underline or right side line | hardly ever supported |
61 | ideogram double underline or double line on the right side | hardly ever supported |
62 | ideogram overline or left side line | hardly ever supported |
63 | ideogram double overline or double line on the left side | hardly ever supported |
64 | ideogram stress marking | hardly ever supported |
90–99 | Set foreground color, high intensity | aixterm (not in standard) |
100–109 | Set background color, high intensity | aixterm (not in standard) |
Read more about this topic: ANSI Escape Code
Famous quotes containing the word codes:
“Thou hast a voice, great Mountain, to repeal
Large codes of fraud and woe; not understood
By all, but which the wise, and great, and good
Interpret, or make felt, or deeply feel.”
—Percy Bysshe Shelley (17921822)