kristofer sweger Home
ANSIPLUS Home


Erase, Insert, Delete and Fill

Esc [#;#J  Clear the current screen page

The Esc [J escape sequence is used to erase the current screen page, filling it with blank spaces using the current colors. Esc [0J fills the screen from the cursor to the end, Esc [1J fills from the top of the screen to the cursor position, and Esc [2J clears the entire screen. To fill the screen with a character other than a blank space, ANSIPLUS allows a second parameter, which is the numeric character code for filling the screen. For example:

Esc [2J Clear the entire screen
Esc [1J Clear the screen up to, but not including, the cursor position
Esc [2;"*"J Fill the screen with asterisks (stars)

Esc [#;#;#K  Clear the current screen line

The Esc [K escape sequence erases the current line. Esc [0K erases from the cursor to the end of the line, Esc [1K erases from the start of the line to the cursor position, and Esc [2K erases the entire line. ANSIPLUS allows up to two extra parameters for this function. The optional second parameter is the maximum number of characters to erase from the cursor position, so that less than the entire line in either direction can be cleared. The optional third parameter is the ASCII character code for filling the erased area. For example:

Esc [K Clear the current line starting at the cursor position
Esc [1K Clear the current line up to, but not including, the cursor position
Esc [0;20K Clear 20 characters starting at the cursor position
Esc [1;10;"X"K Fill the 10 character positions before the cursor with "X"

Esc [#;#X  Erase characters on the current screen line

The Esc [X escape sequence erases one or more characters on the current line, starting at the current cursor position. The first parameter, if supplied, is the number of characters to erase. ANSIPLUS also allows a second parameter for this function, which is the ASCII character code for filling the erased area. For example:

Esc [X Erase the single character at the cursor position
Esc [20X Erase 20 characters starting at the cursor position
Esc [10;"*"X Fill 10 characters starting at the cursor with "*"

Esc [X is a standard ANSI terminal function that is not included in the ANSI.sys driver.

Esc [#;#L  Insert lines on the screen
Esc [!#;#L  Insert lines from scroll-back
Esc [#;#M  Delete lines from the screen
Esc [!#;#M  Delete lines and add to scroll-back
Esc [#;#@  Insert characters on a line
Esc [#;#P  Delete characters from a line

Four of the six insert and delete functions, Esc [L, Esc [M, Esc [@ and Esc [P are standard ANSI terminal control functions that are included in ANSIPLUS but are not in the MS-DOS ANSI.sys driver. The ANSIPLUS-only function Esc [!L inserts the most recently saved line(s) from scroll-back instead of inserting blank lines, and Esc [!M copies lines to scroll-back before they are deleted. These two functions can be used in combination to move lines from one place on the screen to another in text modes.

The first parameter for each escape sequence is the number of lines or characters to insert or delete. If omitted, a value of one is assumed. ANSIPLUS extends each of these functions to allow a second parameter. The second optional parameter for Esc [L, Esc [!L, Esc [M and Esc [!M is the number of lines to be scrolled when inserting or deleting the line(s). For Esc [@ and Esc [P the second parameter is the number of characters to be shifted on the line by the insertion or deletion. If omitted, the current screen size (rows or columns) is assumed. For example:

Esc [L Insert a single line at the cursor position
Esc [!2L Insert the two most recent lines from scroll-back at the cursor position
Esc [2M Delete 2 lines starting at the cursor position
Esc [1;20P Delete 1 character by shifting the 19 following characters left

Esc [#b  Repeat last output character

The Esc [b escape sequence repeats the last character that was output before the escape sequence zero or more times, starting at the current cursor position. The first parameter, if supplied, is the number repetitions. If omitted, the character is repeated once. Esc [b is a standard ANSI terminal function that is not included in the ANSI.sys driver.


© Copyright 2000-2007, Kristofer Sweger. All rights reserved.
Rev. 10/16/07