ANSI codes define functions that change display graphics, control cursor movement, and
reassign keys. An ANSI escape sequence is a sequence of ASCII characters, the first two of which
are the escape character (1Bh) and the left-bracket character (5Bh). The
character or characters following the escape and left-bracket characters
specify an alphanumeric code that controls a keyboard or display function.
ANSI escape sequences distinguish between uppercase and lowercase letters;
for example,"A" and "a" have completely different meanings.
Below, we present the commands used for cursur positioning. To see the complete set check our main page here
Parameters used in ANSI escape sequences
- Pn - Numeric parameter. Specifies a decimal number.
- Ps - Selective parameter. Specifies a decimal number that you use to select a function. You can specify more than one function by separating the parameters with semicolons.
- PL - Line parameter. Specifies a decimal number that represents one of the lines on your display or on another device.
- Pc - Column parameter. Specifies a decimal number that represents one of the columns on your screen or on another device.
ANSI escape sequences for cursor movement, graphics, and keyboard settings
In the following list of ANSI escape sequences, the abbreviation ESC represents the ASCII escape character 27 (1Bh), which appears at the beginning of each escape sequence.
- ESC[PL;PcH - Cursor Position: Moves the cursor to the specified position (coordinates). If you do not specify a position, the cursor moves to the home position: the upper-left corner of the screen (line 0, column 0). This escape sequence works the same way as the following Cursor Position escape sequence. Example: ESC[5;7H moves the cursor to line 5 column 7.
- ESC[PL;Pcf - Cursor Position: Works the same way as the preceding Cursor Position escape sequence. Example: ESC[4;9f moves the cursor to line 4, column 9.
- ESC[PnA - Cursor Up: Moves the cursor up by the specified number of lines without changing columns. If the cursor is already on the top line, ANSI.SYS ignores this sequence. Example: ESC[3A moves the cursor up 3 lines.
- ESC[PnB - Cursor Down: Moves the cursor down by the specified number of lines without changing columns. If the cursor is already on the bottom line, ANSI.SYS ignores this sequence. Example: ESC[2B moves the cursor down 2 lines.
- ESC[PnC - Cursor Forward: Moves the cursor forward by the specified number of columns without changing lines. If the cursor is already in the rightmost column, ANSI.SYS ignores this sequence. Example: ESC[5C moves the cursor to the right 5 columns.
- ESC[PnD - Cursor Backward: Moves the cursor back by the specified number of columns without changing lines. If the cursor is already in the leftmost column, ANSI.SYS ignores this sequence. Example: ESC[4D moves the cursor to the left 4 columns.
- ESC[s - Save Cursor Position: Saves the current cursor position. You can move the cursor to the saved cursor position by using the Restore Cursor Position sequence. Example: ESC[s saves the current cursor position.
- ESC[u - Restore Cursor Position: Returns the cursor to the position stored by the Save Cursor Position sequence. Example: ESC[u moves the cursor to the position stored using the "save cursor position" command.
- ESC[J - Erase Display: Clears the screen from the cursor to the end of the screen. Example: ESC[J clears the screen from the cursor to the end of the screen.
- ESC[2J - Erase Display: Clears the screen and moves the cursor to the home position (line 0, column 0). Example: ESC[2J clears the screen and moves the cursor to line 0, column 0.
- ESC[K - Erase Line: Clears all characters from the cursor position to the end of the line (including the character at the cursor position). Example: ESC[K clears the line from the current cursor position to the end of the line.
- ESC[2K - Erase Line: Clears all characters on the line. Example: ESC[2K clears the current line.
|